Java Reference
In-Depth Information
You can give a thread a name, either as a String parameter to the con-
structor or as the parameter of a setName invocation. You can get the
current name of a thread by invoking getName . Thread names are strictly
for programmer conveniencethey are not used by the runtime system-
but a thread must have a name and so if none is specified, the runtime
system will give it one, usually using a simple numbering scheme like
Thread-1 , Thread-2 , and so on.
You can obtain the Thread object for the currently running thread by in-
voking the static method THRead.currentThread . There is always a cur-
rently running thread, even if you did not create one explicitly main itself
is executed by a thread created by the runtime system.
Exercise 14.1 : Write a program that displays the name of the thread
that executes main .
 
Search WWH ::




Custom Search