posted 15 years ago
When you run the code as it is you get this :
thread main name :main
thread name :Thread-1
thread name :Thread-1
The first line is the System.out.println statement you have at line 24 in your source code, it shows the current Thread which is main. Note that to be correct and avoid warnings must use Thread.currentThread() , because this method is static for class Thread.
The other two lines are generated by the System.out.println statement inside the for loop in the run method.
In this code you are launching 2 threads:
- 1 thread instance of Thread class, which doesn't print anything to the screen.
- 1 thread instance of ThreadA class
If you comment out the line 19 and 20 you get this:
thread main name :main
thread name :Thread-0
thread name :Thread-0
Because you are launching just one thread, a instance of ThreadA class.