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 classThreadimplements Runnable { // public constants public static final intMIN_PRIORITY; public static final intNORM_PRIORITY; public static final intMAX_PRIORITY; // static methods public static native intactiveCount(); public static native ThreadcurrentThread(); public static native voidsleep(long millis) throws java.lang.InterruptedException; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access