Summary
The pages of this lesson have provided a lot of information
about using threads in the Java development environment.
Threads are supported by various components of the Java
development environment and it can be confusing where to
look for the features that you need. This page summarizes
where in the Java environment you can find various classes,
methods, and language features that participate in the
Java threads story.
Package Support of Threads
-
java.lang.Thread
-
In the Java development enviroment, threads are objects that
derive from java.lang's Thread class. The Thread class defines
and implements Java threads. You can subclass the Thread class
to provide your own thread implementations or you can use
the Runnable interface.
-
java.lang.Runnable
-
The Java language library also defines the Runnable interface
which allows any arbitrary object to provide the body (the
run() method)
for a Thread.
-
java.lang.Object
-
The base level class, Object, defines three methods you can use to
synchronize methods around a condition variable:
wait(),
notify(), and notifyAll().
-
java.lang.ThreadGroup
-
All threads belong to a thread group which typically contains
related threads. The ThreadGroup class in the java.lang package implements
groups of threads.
-
java.lang.Death
-
A thread is normally killed by throwing a ThreadDeath object
at it. It is rare that any thread need catch ThreadDeath to do any
cleaning up before actually dying.
Language Support of Threads
The Java language has two keywords related to the synchronization of threads:
volatile (which is not yet implemented) and synchronized.
Both of these language features help ensure the integrity of data that is
shared between two concurrently running threads.
Multithreaded Programs
discusses thread synchronization issues.
Runtime Support of Threads
The Java runtime system contains the scheduler that is responsible
for running all the existing threads. The Java scheduler uses
a fixed priority scheduling algorithm which boils down to this
simple rule:
Rule: At any give time, the highest priority runnable thread is running.