Name: bsC130419 Date: 07/24/2001
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
Have a look at the JavaDoc for the java.lang.Thread default constructor. The
Java example is absolute nonsense, here it is with my comments:
class plain01 implements Runnable {
String name;
plain01() {
name = null; // NOT NEEDED
}
plain01(String s) {
name = s;
}
public void run() {
if (name == null)
// THIS LINE BELOW IS NOT TRUE - NO THREAD HAS BEEN CREATED
// ANY OBJECT COULD CALL new plain01().run()
System.out.println("A new thread created");
else
// AND AGAIN, NO THREAD HAS BEEN CREATED, JUST A plain01
System.out.println("A new thread with name " + name +
" created");
}
}
class threadtest01 {
public static void main(String args[] ) {
int failed = 0 ;
Thread t1 = new Thread();
if (t1 != null) // t1 CANNOT BE NULL AT THIS POINT
System.out.println("new Thread() succeed");
else {
System.out.println("new Thread() failed");
failed++;
}
}
}
THe ThreadTest01 class does not use plain01 - I'm guessing the intention. But
the javadoc states: "Threads created this way [no arg constructor] must have
overridden their run() method to actually do anything". The above example
doesn't do that at all.
(Review ID: 127945)
======================================================================
- duplicates
-
JDK-4629457 Thread documentation bugs: bad example in 1.3.1 API, setPriority not clear
-
- Closed
-