Download java source code from java.threads.zip.
Java documentation: Thread
Java tutorial Concurrency
Thread
Class and Runnable
InterfaceThread
encapsulates an execution thread and
provides methods to manage thread execution. The
Runnable
interface defines only the method
run()
. The run
method establishes the entry
point for another concurrent thread of execution within your program.
This thread will end when run()
returns.
After you have created a class that implements
Runnable
, you can instantiate an object of type
Thread
on an object of that class.
Some simple improvements:
You can extend the Thread
class, rather than
implement Runnable
. You will need to override the
run()
method. You must also call start()
to
begin execution of the new thread.
Maintained by John Loomis, last updated 20 November 2012