Java Thread Constructors
Overloaded Thread Constructors
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
, which is the entry point to the thread. It is defined like this:
void run( )
Threads that you create must implement this method.
Thread creates a new thread of execution. It implements Runnable and defines the following commonly used constructors:
Thread(Runnable threadOb, 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
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.
The following constants are defined by Thread:
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( ),
These methods were deprecated because they are unstable.
is deprecated, because it calls
and these methods can cause deadlock