Java.lang.Object Java.lang.Thread All implemented interfaces:runnable Direct known Subclasses:forkjoinworkerthread
public class Thread
extends Object
implements Runnable
A thread is a thread of the execution in a. The Java Virtual Machine allows a application to have multiple threads of execution running.
Every thread has a priority. Threads with higher priority are executed into preference to Threads with lower. Each thread may or could not also is marked as a daemon. When code running in some thread creates a new thread object, the new thread has it priority initially set equal to the P Riority 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 are 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:the exit method of Class Runti Me has been called and the security manager has permitted the exit operation to take place. All threads this are not daemon threads have died, either by returning from the "call" to "run" or by throwing a E Xception that propagates beyond the run method.
There are two ways to create a new thread of execution. One is to declare a class to be a subclass of Thread. This is subclass should override the Run method of class Thread. An instance of the subclass can then is allocated and started. For example, a thread that computes primes larger than a stated value could is 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 are to declare a class that implements the Runnable interface. This class then implements the Run method. An instance of the class can then is allocated, passed as a 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 isn't specified when a thread is created, a new name is generated for it.
Unless otherwise noted, passing a null argument to a constructor or method in this class would cause a nullpointerexception To be thrown. since:jdk1.0-also:runnable, runtime.exit (int), run (), Stop ()
Article source: http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html