Name

java.lang.Thread

Synopsis

This class is a scaled-down version of the J2SE Thread class, which represents a system thread in the Java virtual machine. Classes can create threads by either extending the Thread class and providing a run() method, or passing a Runnable object into the Thread constructor. Threads execute when the start() method is called, and will continue until the end of the run() method, unless run() is interrupted. The isAlive() method returns a boolean that indicates if the current thread is executing.

activeCount() returns the total number of threads active. The getPriority() and setPriority() methods can access the integer priority level of the thread, which can be used in conjunction with the three constants, MIN_PRIORITY, NORM_PRIORITY, and MAX_PRIORITY. currentThread() returns a reference to the thread that is currently active. sleep() will cause the current thread to halt execution for the specified amount of time, while yield() gives up control to other threads of equal priority that are waiting to run. Finally, join() will suspend execution until the target thread has completed or is interrupted.

public classThread implements Runnable {
   // public constants
   public static final int MIN_PRIORITY;
   public static final int NORM_PRIORITY;
   public static final int MAX_PRIORITY;

   // static methods
   public static native int activeCount();
   public static native Thread currentThread();
   public static native void sleep(long millis) throws java.lang.InterruptedException; ...

Get Wireless Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.