Intel

Developer Zone

Thread

java.lang

Class Thread



  • public class Thread
    extends Object
    A Thread 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 main Thread running when it is started; typically, there are several others for housekeeping. The application might decide to launch additional Threads for specific purposes.

    Threads 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 in Object also allow Threads to cooperate.

    There are basically two main ways of having a Thread execute application code. One is providing a new class that extends Thread and overriding its run() method. The other is providing a new Thread instance with a Runnable object during its creation. In both cases, the #start() method must be called to actually execute the new Thread.

    Each Thread has an integer priority that basically determines the amount of CPU time the Thread gets. It can be set using the #setPriority(int) method. A Thread 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.
    • Method Summary

      Methods
      Modifier and Type Method and Description
      void run()
      Calls the run() method of the Runnable object the receiver holds.
    • Constructor Detail

      • Thread

        public Thread()
        Constructs a new Thread with no runnable object and a newly generated name. The new Thread will belong to the same ThreadGroup as the Thread calling this constructor.
        See Also:
        ThreadGroup
    • Method Detail

      • run

        public void run()
        Calls the run() method of the Runnable object the receiver holds. If no Runnable is set, does nothing.
        See Also:
        Thread#start