Thread.Thread

Thread.Thread

Class Overview | Class Members | This Package | All Packages

Syntax 1
public Thread()
Description
Allocates a new Thread object. This constructor has the same effect as Thread(null, null, gname), where gname is a newly generated name. Automatically generated names are of the form "Thread-"+n, where n is an integer.

Threads created this way must have overridden their run() method to actually do anything. An example illustrating this method being used follows:

     import java.lang.*; 
     class plain01 implements Runnable {
         String name; 
         plain01() {
             name = null;
         }
         plain01(String s) {
             name = s;
         }
         public void run() {
             if (name == null)
                 System.out.println("A new thread created");
             else
                 System.out.println("A new thread with name " + name +
                                    " created");
         }
     }
     class threadtest01 {
         public static void main(String args[] ) {
             int failed = 0 ;
             Thread t1 = new Thread();  
             if (t1 != null)
                 System.out.println("new Thread() succeed");
             else {
                 System.out.println("new Thread() failed"); 
                 failed++; 
             }
         }
     }
 

See Also
Thread



Syntax 2
public Thread( Runnable target )
Parameters
target
the object whose run method is called.
Description
Allocates a new Thread object. This constructor has the same effect as Thread(null, target, gname), where gname is a newly generated name. Automatically generated names are of the form "Thread-"+n, where n is an integer.

See Also
Thread



Syntax 3
public Thread( ThreadGroup group, Runnable target )
Parameters
group
the thread group.
target
the object whose run method is called.
Description
Allocates a new Thread object. This constructor has the same effect as Thread(group, target, gname), where gname is a newly generated name. Automatically generated names are of the form "Thread-"+n, where n is an integer.

Exceptions
SecurityException if the current thread cannot create a thread in the specified thread group.
See Also
Thread



Syntax 4
public Thread( String name )
Parameters
name
the name of the new thread.
Description
Allocates a new Thread object. This constructor has the same effect as Thread(null, null, name).

See Also
Thread



Syntax 5
public Thread( ThreadGroup group, String name )
Parameters
group
the thread group.
name
the name of the new thread.
Description
Allocates a new Thread object. This constructor has the same effect as Thread(group, null, name)

Exceptions
SecurityException if the current thread cannot create a thread in the specified thread group.
See Also
Thread



Syntax 6
public Thread( Runnable target, String name )
Parameters
target
the object whose run method is called.
name
the name of the new thread.
Description
Allocates a new Thread object. This constructor has the same effect as Thread(null, target, name).

See Also
Thread



Syntax 7
public Thread( ThreadGroup group, Runnable target, String name )
Parameters
group
the thread group.
target
the object whose run method is called.
name
the name of the new thread.
Description
Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group.

If group is not null, the checkAccess method of that thread group is called with no arguments; this may result in throwing a SecurityException; if group is null, the new process belongs to the same group as the thread that is creating the new thread.

If the target argument is not null, the run method of the target is called when this thread is started. If the target argument is null, this thread's run method is called when this thread is started.

The priority of the newly created thread is set equal to the priority of the thread creating it, that is, the currently running thread. The method setPriority may be used to change the priority to a new value.

The newly created thread is initially marked as being a daemon thread if and only if the thread creating it is currently marked as a daemon thread. The method setDaemon may be used to change whether or not a thread is a daemon.

Exceptions
SecurityException if the current thread cannot create a thread in the specified thread group.
See Also
run, run, setDaemon, setPriority, checkAccess