Class Thread
- java.lang.Object
-
- java.lang.Thread
-
public class Thread extends Object
AThread
is a concurrent unit of execution. It has its own call stack for methods being invoked, their arguments and local variables. Each virtual machine instance has at least one mainThread
running when it is started; typically, there are several others for housekeeping. The application might decide to launch additionalThread
s for specific purposes.Thread
s in the same VM interact and synchronize by the use of shared objects and monitors associated with these objects. Synchronized methods and part of the API inObject
also allowThread
s to cooperate.There are basically two main ways of having a
Thread
execute application code. One is providing a new class that extendsThread
and overriding itsrun()
method. The other is providing a newThread
instance with aRunnable
object during its creation. In both cases, the#start()
method must be called to actually execute the newThread
.Each
Thread
has an integer priority that basically determines the amount of CPU time theThread
gets. It can be set using the#setPriority(int)
method. AThread
can also be made a daemon, which makes it run in the background. The latter also affects VM termination behavior: the VM does not terminate automatically as long as there are non-daemon threads running.- See Also:
Object
,ThreadGroup
-
-
Constructor Summary
Constructors Constructor and Description Thread()
Constructs a new Thread with no runnable object and a newly generated name.
-