Threads of Control |
By now, you are familiar with threads and you've seen a simple Java application that runs two threads concurrently. This page introduces you to several features specific to Java threads and provides you with links to pages that talk about each feature in detail.Java threads are implemented by the
Thread
class, which is part of thejava.lang
package. TheThread
class implements a system-independent definition of Java threads. But under the hood, the actual implementation of concurrent operation is provided by a system-specific implementation. For most programming needs, the underlying implementation doesn't matter. You can ignore the underlying implementation and program to the thread API described in this lesson and in the other documentation provided with the Java system.
- Thread Body
- All of the action takes place in the thread's body--the thread's
run
method. You can provide the body to a Thread in one of two ways: by subclassing the Thread class and overriding itsrun
method, or by creating aThread
with aRunnable
object as its target.- Thread State
- Throughout its life, a Java thread is in one of several states. A thread's state indicates what the
Thread
is doing and what it is capable of doing at that time of its life: Is it running? Is it sleeping? Is it dead?- Thread Priority
- A thread's priority tells the Java thread scheduler when this thread should run in relation to other threads.
- Daemon Threads
- Daemon threads are those that provide a service for other threads in the system. Any Java thread can be a daemon thread.
- Thread Group
- All threads belong to a thread group.
ThreadGroup
, ajava.lang
class, defines and implements the capabilities of a group of related threads.
Threads of Control |