Threads II -(the life of a Thread)


The wait()-notify() methods offer a way of synchronized(ing) the execution of two or more Threads. However, this synchronization is on a per instance (or per class) basis. There is a second pair of methods, suspend()- resume(), that can be used to synchronize behavior at the Thread level rather than the instance level. Note: the methods that call suspend() and resume() are not synchronized.

Here is an example that uses these methods.

Completing this, too brief, introduction to Java Threads, here is a state change diagram showing the possible life paths of a Thread.

 

 

 


Next, here is an example of two threads that are running at the "same" time
There is one other important point that needs to be looked at. The stop() and start() for Applet and Thread are unrelated as the next example shows.