Using the Runnable interface to create simple threads.
Output will vary:
View Java Applet Source
Note: This is an example of creating simple threads in Java. It does not include features such as the wait(), notify(), and notifyAll() methods from the Object class. In a normal environment, one thread usually has to wait for another thread to complete its task before it can perform. Ideally, the threads need to communicate between each other when they have completed their task, or else a deadlock could occur.
For more information on threads, view Sun Microsystems' on-line documentation. |