java.lang
Class Thread

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.lang.Thread
All Implemented Interfaces:
Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable

public class Thread
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable

A thread is a thread of execution in a program. The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.

Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority. Each thread may or may not also be marked as a daemon. When code running in some thread creates a new Thread object, the new thread has its priority initially set equal to the priority of the creating thread, and is a daemon thread if and only if the creating thread is a daemon.

When a Java Virtual Machine starts up, there is usually a single non-daemon thread (which typically calls the method named main of some designated class). The Java Virtual Machine continues to execute threads until either of the following occurs:

There are two ways to create a new thread of execution. One is to declare a class to be a subclass of Thread. This subclass should override the run method of class Thread. An instance of the subclass can then be allocated and started. For example, a thread that computes primes larger than a stated value could be written as follows:


     class PrimeThread extends Thread {
         long minPrime;
         PrimeThread(long minPrime) {
             this.minPrime = minPrime;
         }
 
         public void run() {
             // compute primes larger than minPrime
              . . .
         }
     }
 

The following code would then create a thread and start it running:

     PrimeThread p = new PrimeThread(143);
     p.start();
 

The other way to create a thread is to declare a class that implements the Runnable interface. That class then implements the run method. An instance of the class can then be allocated, passed as an argument when creating Thread, and started. The same example in this other style looks like the following:


     class PrimeRun implements Runnable {
         long minPrime;
         PrimeRun(long minPrime) {
             this.minPrime = minPrime;
         }
 
         public void run() {
             // compute primes larger than minPrime
              . . .
         }
     }
 

The following code would then create a thread and start it running:

     PrimeRun p = new PrimeRun(143);
     new Thread(p).start();
 

Every thread has a name for identification purposes. More than one thread may have the same name. If a name is not specified when a thread is created, a new name is generated for it.

Since:
JDK1.0
See Also:
Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable , Runtime.exit(int) sample code for java.lang.Runtime.exit(int) definition code for java.lang.Runtime.exit(int) , run() sample code for java.lang.Thread.run() definition code for java.lang.Thread.run() , stop() sample code for java.lang.Thread.stop() definition code for java.lang.Thread.stop()

Nested Class Summary
static class Thread.State sample code for java.lang.Thread.State definition code for java.lang.Thread.State
          A thread state.
static interface Thread.UncaughtExceptionHandler sample code for java.lang.Thread.UncaughtExceptionHandler definition code for java.lang.Thread.UncaughtExceptionHandler
          Interface for handlers invoked when a Thread abruptly terminates due to an uncaught exception.
 
Field Summary
static int MAX_PRIORITY sample code for java.lang.Thread.MAX_PRIORITY definition code for java.lang.Thread.MAX_PRIORITY
          The maximum priority that a thread can have.
static int MIN_PRIORITY sample code for java.lang.Thread.MIN_PRIORITY definition code for java.lang.Thread.MIN_PRIORITY
          The minimum priority that a thread can have.
static int NORM_PRIORITY sample code for java.lang.Thread.NORM_PRIORITY definition code for java.lang.Thread.NORM_PRIORITY
          The default priority that is assigned to a thread.
 
Constructor Summary
Thread sample code for java.lang.Thread.Thread() definition code for java.lang.Thread.Thread() ()
          Allocates a new Thread object.
Thread sample code for java.lang.Thread.Thread(java.lang.Runnable) definition code for java.lang.Thread.Thread(java.lang.Runnable) (Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable  target)
          Allocates a new Thread object.
Thread sample code for java.lang.Thread.Thread(java.lang.Runnable, java.lang.String) definition code for java.lang.Thread.Thread(java.lang.Runnable, java.lang.String) (Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable  target, String sample code for java.lang.String definition code for java.lang.String  name)
          Allocates a new Thread object.
Thread sample code for java.lang.Thread.Thread(java.lang.String) definition code for java.lang.Thread.Thread(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  name)
          Allocates a new Thread object.
Thread sample code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable) definition code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable) (ThreadGroup sample code for java.lang.ThreadGroup definition code for java.lang.ThreadGroup  group, Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable  target)
          Allocates a new Thread object.
Thread sample code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String) definition code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String) (ThreadGroup sample code for java.lang.ThreadGroup definition code for java.lang.ThreadGroup  group, Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable  target, String sample code for java.lang.String definition code for java.lang.String  name)
          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.
Thread sample code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String, long) definition code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String, long) (ThreadGroup sample code for java.lang.ThreadGroup definition code for java.lang.ThreadGroup  group, Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable  target, String sample code for java.lang.String definition code for java.lang.String  name, long stackSize)
          Allocates a new Thread object so that it has target as its run object, has the specified name as its name, belongs to the thread group referred to by group, and has the specified stack size.
Thread sample code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.String) definition code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.String) (ThreadGroup sample code for java.lang.ThreadGroup definition code for java.lang.ThreadGroup  group, String sample code for java.lang.String definition code for java.lang.String  name)
          Allocates a new Thread object.
 
Method Summary
static int activeCount sample code for java.lang.Thread.activeCount() definition code for java.lang.Thread.activeCount() ()
          Returns the number of active threads in the current thread's thread group.
 void checkAccess sample code for java.lang.Thread.checkAccess() definition code for java.lang.Thread.checkAccess() ()
          Determines if the currently running thread has permission to modify this thread.
 int countStackFrames sample code for java.lang.Thread.countStackFrames() definition code for java.lang.Thread.countStackFrames() ()
          Deprecated. The definition of this call depends on suspend() sample code for java.lang.Thread.suspend() definition code for java.lang.Thread.suspend() , which is deprecated. Further, the results of this call were never well-defined.
static Thread sample code for java.lang.Thread definition code for java.lang.Thread currentThread sample code for java.lang.Thread.currentThread() definition code for java.lang.Thread.currentThread() ()
          Returns a reference to the currently executing thread object.
 void destroy sample code for java.lang.Thread.destroy() definition code for java.lang.Thread.destroy() ()
          Deprecated. This method was originally designed to destroy this thread without any cleanup. Any monitors it held would have remained locked. However, the method was never implemented. If if were to be implemented, it would be deadlock-prone in much the manner of suspend() sample code for java.lang.Thread.suspend() definition code for java.lang.Thread.suspend() . If the target thread held a lock protecting a critical system resource when it was destroyed, no thread could ever access this resource again. If another thread ever attempted to lock this resource, deadlock would result. Such deadlocks typically manifest themselves as "frozen" processes. For more information, see Why are Thread.stop, Thread.suspend and Thread.resume Deprecated?.
static void dumpStack sample code for java.lang.Thread.dumpStack() definition code for java.lang.Thread.dumpStack() ()
          Prints a stack trace of the current thread.
static int enumerate sample code for java.lang.Thread.enumerate(java.lang.Thread[]) definition code for java.lang.Thread.enumerate(java.lang.Thread[]) (Thread sample code for java.lang.Thread definition code for java.lang.Thread [] tarray)
          Copies into the specified array every active thread in the current thread's thread group and its subgroups.
static Map sample code for java.util.Map definition code for java.util.Map <Thread sample code for java.lang.Thread definition code for java.lang.Thread ,StackTraceElement sample code for java.lang.StackTraceElement definition code for java.lang.StackTraceElement []> getAllStackTraces sample code for java.lang.Thread.getAllStackTraces() definition code for java.lang.Thread.getAllStackTraces() ()
          Returns a map of stack traces for all live threads.
 ClassLoader sample code for java.lang.ClassLoader definition code for java.lang.ClassLoader getContextClassLoader sample code for java.lang.Thread.getContextClassLoader() definition code for java.lang.Thread.getContextClassLoader() ()
          Returns the context ClassLoader for this Thread.
static Thread.UncaughtExceptionHandler sample code for java.lang.Thread.UncaughtExceptionHandler definition code for java.lang.Thread.UncaughtExceptionHandler getDefaultUncaughtExceptionHandler sample code for java.lang.Thread.getDefaultUncaughtExceptionHandler() definition code for java.lang.Thread.getDefaultUncaughtExceptionHandler() ()
          Returns the default handler invoked when a thread abruptly terminates due to an uncaught exception.
 long getId sample code for java.lang.Thread.getId() definition code for java.lang.Thread.getId() ()
          Returns the identifier of this Thread.
 String sample code for java.lang.String definition code for java.lang.String getName sample code for java.lang.Thread.getName() definition code for java.lang.Thread.getName() ()
          Returns this thread's name.
 int getPriority sample code for java.lang.Thread.getPriority() definition code for java.lang.Thread.getPriority() ()
          Returns this thread's priority.
 StackTraceElement sample code for java.lang.StackTraceElement definition code for java.lang.StackTraceElement [] getStackTrace sample code for java.lang.Thread.getStackTrace() definition code for java.lang.Thread.getStackTrace() ()
          Returns an array of stack trace elements representing the stack dump of this thread.
 Thread.State sample code for java.lang.Thread.State definition code for java.lang.Thread.State getState sample code for java.lang.Thread.getState() definition code for java.lang.Thread.getState() ()
          Returns the state of this thread.
 ThreadGroup sample code for java.lang.ThreadGroup definition code for java.lang.ThreadGroup getThreadGroup sample code for java.lang.Thread.getThreadGroup() definition code for java.lang.Thread.getThreadGroup() ()
          Returns the thread group to which this thread belongs.
 Thread.UncaughtExceptionHandler sample code for java.lang.Thread.UncaughtExceptionHandler definition code for java.lang.Thread.UncaughtExceptionHandler getUncaughtExceptionHandler sample code for java.lang.Thread.getUncaughtExceptionHandler() definition code for java.lang.Thread.getUncaughtExceptionHandler() ()
          Returns the handler invoked when this thread abruptly terminates due to an uncaught exception.
static boolean holdsLock sample code for java.lang.Thread.holdsLock(java.lang.Object) definition code for java.lang.Thread.holdsLock(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  obj)
          Returns true if and only if the current thread holds the monitor lock on the specified object.
 void interrupt sample code for java.lang.Thread.interrupt() definition code for java.lang.Thread.interrupt() ()
          Interrupts this thread.
static boolean interrupted sample code for java.lang.Thread.interrupted() definition code for java.lang.Thread.interrupted() ()
          Tests whether the current thread has been interrupted.
 boolean isAlive sample code for java.lang.Thread.isAlive() definition code for java.lang.Thread.isAlive() ()
          Tests if this thread is alive.
 boolean isDaemon sample code for java.lang.Thread.isDaemon() definition code for java.lang.Thread.isDaemon() ()
          Tests if this thread is a daemon thread.
 boolean isInterrupted sample code for java.lang.Thread.isInterrupted() definition code for java.lang.Thread.isInterrupted() ()
          Tests whether this thread has been interrupted.
 void join sample code for java.lang.Thread.join() definition code for java.lang.Thread.join() ()
          Waits for this thread to die.
 void join sample code for java.lang.Thread.join(long) definition code for java.lang.Thread.join(long) (long millis)
          Waits at most millis milliseconds for this thread to die.
 void join sample code for java.lang.Thread.join(long, int) definition code for java.lang.Thread.join(long, int) (long millis, int nanos)
          Waits at most millis milliseconds plus nanos nanoseconds for this thread to die.
 void resume sample code for java.lang.Thread.resume() definition code for java.lang.Thread.resume() ()
          Deprecated. This method exists solely for use with suspend() sample code for java.lang.Thread.suspend() definition code for java.lang.Thread.suspend() , which has been deprecated because it is deadlock-prone. For more information, see Why are Thread.stop, Thread.suspend and Thread.resume Deprecated?.
 void run sample code for java.lang.Thread.run() definition code for java.lang.Thread.run() ()
          If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.
 void setContextClassLoader sample code for java.lang.Thread.setContextClassLoader(java.lang.ClassLoader) definition code for java.lang.Thread.setContextClassLoader(java.lang.ClassLoader) (ClassLoader sample code for java.lang.ClassLoader definition code for java.lang.ClassLoader  cl)
          Sets the context ClassLoader for this Thread.
 void setDaemon sample code for java.lang.Thread.setDaemon(boolean) definition code for java.lang.Thread.setDaemon(boolean) (boolean on)
          Marks this thread as either a daemon thread or a user thread.
static void setDefaultUncaughtExceptionHandler sample code for java.lang.Thread.setDefaultUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) definition code for java.lang.Thread.setDefaultUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) (Thread.UncaughtExceptionHandler sample code for java.lang.Thread.UncaughtExceptionHandler definition code for java.lang.Thread.UncaughtExceptionHandler  eh)
          Set the default handler invoked when a thread abruptly terminates due to an uncaught exception, and no other handler has been defined for that thread.
 void setName sample code for java.lang.Thread.setName(java.lang.String) definition code for java.lang.Thread.setName(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  name)
          Changes the name of this thread to be equal to the argument name.
 void setPriority sample code for java.lang.Thread.setPriority(int) definition code for java.lang.Thread.setPriority(int) (int newPriority)
          Changes the priority of this thread.
 void setUncaughtExceptionHandler sample code for java.lang.Thread.setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) definition code for java.lang.Thread.setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) (Thread.UncaughtExceptionHandler sample code for java.lang.Thread.UncaughtExceptionHandler definition code for java.lang.Thread.UncaughtExceptionHandler  eh)
          Set the handler invoked when this thread abruptly terminates due to an uncaught exception.
static void sleep sample code for java.lang.Thread.sleep(long) definition code for java.lang.Thread.sleep(long) (long millis)
          Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.
static void sleep sample code for java.lang.Thread.sleep(long, int) definition code for java.lang.Thread.sleep(long, int) (long millis, int nanos)
          Causes the currently executing thread to sleep (cease execution) for the specified number of milliseconds plus the specified number of nanoseconds.
 void start sample code for java.lang.Thread.start() definition code for java.lang.Thread.start() ()
          Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
 void stop sample code for java.lang.Thread.stop() definition code for java.lang.Thread.stop() ()
          Deprecated. This method is inherently unsafe. Stopping a thread with Thread.stop causes it to unlock all of the monitors that it has locked (as a natural consequence of the unchecked ThreadDeath exception propagating up the stack). If any of the objects previously protected by these monitors were in an inconsistent state, the damaged objects become visible to other threads, potentially resulting in arbitrary behavior. Many uses of stop should be replaced by code that simply modifies some variable to indicate that the target thread should stop running. The target thread should check this variable regularly, and return from its run method in an orderly fashion if the variable indicates that it is to stop running. If the target thread waits for long periods (on a condition variable, for example), the interrupt method should be used to interrupt the wait. For more information, see Why are Thread.stop, Thread.suspend and Thread.resume Deprecated?.
 void stop sample code for java.lang.Thread.stop(java.lang.Throwable) definition code for java.lang.Thread.stop(java.lang.Throwable) (Throwable sample code for java.lang.Throwable definition code for java.lang.Throwable  obj)
          Deprecated. This method is inherently unsafe. See stop() sample code for java.lang.Thread.stop() definition code for java.lang.Thread.stop() for details. An additional danger of this method is that it may be used to generate exceptions that the target thread is unprepared to handle (including checked exceptions that the thread could not possibly throw, were it not for this method). For more information, see Why are Thread.stop, Thread.suspend and Thread.resume Deprecated?.
 void suspend sample code for java.lang.Thread.suspend() definition code for java.lang.Thread.suspend() ()
          Deprecated. This method has been deprecated, as it is inherently deadlock-prone. If the target thread holds a lock on the monitor protecting a critical system resource when it is suspended, no thread can access this resource until the target thread is resumed. If the thread that would resume the target thread attempts to lock this monitor prior to calling resume, deadlock results. Such deadlocks typically manifest themselves as "frozen" processes. For more information, see Why are Thread.stop, Thread.suspend and Thread.resume Deprecated?.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.lang.Thread.toString() definition code for java.lang.Thread.toString() ()
          Returns a string representation of this thread, including the thread's name, priority, and thread group.
static void yield sample code for java.lang.Thread.yield() definition code for java.lang.Thread.yield() ()
          Causes the currently executing thread object to temporarily pause and allow other threads to execute.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

MIN_PRIORITY sample code for java.lang.Thread.MIN_PRIORITY

public static final int MIN_PRIORITY
The minimum priority that a thread can have.

See Also:
Constant Field Values

NORM_PRIORITY sample code for java.lang.Thread.NORM_PRIORITY

public static final int NORM_PRIORITY
The default priority that is assigned to a thread.

See Also:
Constant Field Values

MAX_PRIORITY sample code for java.lang.Thread.MAX_PRIORITY

public static final int MAX_PRIORITY
The maximum priority that a thread can have.

See Also:
Constant Field Values
Constructor Detail

Thread sample code for java.lang.Thread() definition code for java.lang.Thread()

public Thread()
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.

See Also:
Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String) sample code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String) definition code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)

Thread sample code for java.lang.Thread(java.lang.Runnable) definition code for java.lang.Thread(java.lang.Runnable)

public Thread(Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable  target)
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.

Parameters:
target - the object whose run method is called.
See Also:
Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String) sample code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String) definition code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)

Thread sample code for java.lang.Thread(java.lang.ThreadGroup, java.lang.Runnable) definition code for java.lang.Thread(java.lang.ThreadGroup, java.lang.Runnable)

public Thread(ThreadGroup sample code for java.lang.ThreadGroup definition code for java.lang.ThreadGroup  group,
              Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable  target)
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.

Parameters:
group - the thread group.
target - the object whose run method is called.
Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if the current thread cannot create a thread in the specified thread group.
See Also:
Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String) sample code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String) definition code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)

Thread sample code for java.lang.Thread(java.lang.String) definition code for java.lang.Thread(java.lang.String)

public Thread(String sample code for java.lang.String definition code for java.lang.String  name)
Allocates a new Thread object. This constructor has the same effect as Thread(null, null, name).

Parameters:
name - the name of the new thread.
See Also:
Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String) sample code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String) definition code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)

Thread sample code for java.lang.Thread(java.lang.ThreadGroup, java.lang.String) definition code for java.lang.Thread(java.lang.ThreadGroup, java.lang.String)

public Thread(ThreadGroup sample code for java.lang.ThreadGroup definition code for java.lang.ThreadGroup  group,
              String sample code for java.lang.String definition code for java.lang.String  name)
Allocates a new Thread object. This constructor has the same effect as Thread(group, null, name)

Parameters:
group - the thread group.
name - the name of the new thread.
Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if the current thread cannot create a thread in the specified thread group.
See Also:
Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String) sample code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String) definition code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)

Thread sample code for java.lang.Thread(java.lang.Runnable, java.lang.String) definition code for java.lang.Thread(java.lang.Runnable, java.lang.String)

public Thread(Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable  target,
              String sample code for java.lang.String definition code for java.lang.String  name)
Allocates a new Thread object. This constructor has the same effect as Thread(null, target, name).

Parameters:
target - the object whose run method is called.
name - the name of the new thread.
See Also:
Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String) sample code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String) definition code for java.lang.Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)

Thread sample code for java.lang.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String) definition code for java.lang.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String)

public Thread(ThreadGroup sample code for java.lang.ThreadGroup definition code for java.lang.ThreadGroup  group,
              Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable  target,
              String sample code for java.lang.String definition code for java.lang.String  name)
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 null and there is a security manager, the group is determined by the security manager's getThreadGroup method. If group is null and there is not a security manager, or the security manager's getThreadGroup method returns null, the group is set to be the same ThreadGroup as the thread that is creating the new thread.

If there is a security manager, its checkAccess method is called with the ThreadGroup as its argument.

In addition, its checkPermission method is called with the RuntimePermission("enableContextClassLoaderOverride") permission when invoked directly or indirectly by the constructor of a subclass which overrides the getContextClassLoader or setContextClassLoader methods. This may result in a SecurityException.

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.

Parameters:
group - the thread group.
target - the object whose run method is called.
name - the name of the new thread.
Throws:
SecurityException sample code for java.lang.SecurityException definition code for java.lang.SecurityException - if the current thread cannot create a thread in the specified thread group or cannot override the context class loader methods.
See Also:
Runnable.run() sample code for java.lang.Runnable.run() definition code for java.lang.Runnable.run() , run() sample code for java.lang.Thread.run() definition code for java.lang.Thread.run() , setDaemon(boolean) sample code for java.lang.Thread.setDaemon(boolean) definition code for java.lang.Thread.setDaemon(boolean) , setPriority(int) sample code for java.lang.Thread.setPriority(int) definition code for java.lang.Thread.setPriority(int) , ThreadGroup.checkAccess() sample code for java.lang.ThreadGroup.checkAccess() definition code for java.lang.ThreadGroup.checkAccess() , SecurityManager.checkAccess(java.lang.Thread) sample code for java.lang.SecurityManager.checkAccess(java.lang.Thread) definition code for java.lang.SecurityManager.checkAccess(java.lang.Thread)

Thread sample code for java.lang.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String, long) definition code for java.lang.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String, long)

public Thread(ThreadGroup sample code for java.lang.ThreadGroup definition code for java.lang.ThreadGroup  group,
              Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable  target,
              String