12/25/2008

Multiple threads

See java.lang.Thread about threads.
Java applications can have multiple threads of execution running concurrently.
(It depends on the thread scheduling of a computer if it has only one CPU.)
 
Implemetation

Extend the
java.lang.Thread class.

Implement the
java.lang.Runnable interface.
 
Life cycle of a thread
Generation
 → Executable → Execution → Finalization

How to make a thread unexecutable
Use these methods.

sleep
wait

How to make a waiting thread executable

Use these methods.
notify
notifyAll

How to have a running thread back to an executable state

Use this method.
yield

Synchronization

Use the synchronize keyword to synchronize multiple threads if necessary.