Threading Model   «Prev 

Java Thread Constructors

Overloaded Thread Constructors

Thread constructor:

public Thread(String threadName)

Here, threadName specifies the name of the thread.

The Runnable Interface

The Runnable interface must be implemented by any class that will initiate a separate thread of execution. Runnable only defines one abstract method, called run( ), which is the entry point to the thread. It is defined like this:
void run( )

Threads that you create must implement this method.

Thread
Thread creates a new thread of execution. It implements Runnable and defines the following commonly used constructors:

Thread( )
Thread(Runnable threadOb)
Thread(Runnable threadOb, String threadName)
Thread(String threadName)
Thread(ThreadGroup groupOb, Runnable threadOb)
Thread(ThreadGroup groupOb, Runnable threadOb, String threadName)
Thread(ThreadGroup groupOb, String threadName)

threadOb is an instance of a class that implements the Runnable interface and defines where execution of the thread will begin.
The name of the thread is specified by threadName.
When a name is not specified, one is created by the Java Virtual Machine. groupOb specifies the thread group to which the new thread will belong. When no thread group is specified, the new thread belongs to the same group as the parent thread.

Thread Constants

The following constants are defined by Thread:
MAX_PRIORITY
MIN_PRIORITY
NORM_PRIORITY
As expected, these constants specify the maximum, minimum, and default thread priorities.
In early versions of Java, the class Thread also included the methods stop( ), suspend( ), and resume( ).
These methods were deprecated because they are unstable.
In addition countStackFrames( ) is deprecated, because it calls suspend( ), and destroy( ), and these methods can cause deadlock.