|20-CS-694||Advanced Programming Techniques||Spring 2012|
All applets have a JButton that says 'Press Me'. Hit that button.
||Stop a thread by setting a flag in the run method. As long as the flag is true a loop continues to run. When the flag is set to false the loop is exited then the run is exited and the thread dies.|
||Stop a thread with interrupt. If a security manager is present, the flag mentioned above can be set from within the checkAccess method. The checkAccess method is invoked when interrupt()() is invoked from the thread object.|
||Stop a thread with interrupted(). The interrupted() method can be used instead of the flag above. Its value becomes true after interrupt() is invoked from the thread object.|
||Stop a thread by invoking checkAccess(). In case a security manager is set, checkAccess() can be invoked to set the flag in run's loop.|
||Deadlock example. This is an attempt to implement a simple handshake. There are two threads and two monitors: one thread is associated with each monitor. Either thread invokes a ping method from its monitor. Inside the ping a confirm method of the other monitor is invoked. When a reply is obtained from both parties, the handshake is complete. Unfortunately this implementation sometimes gets stuck: both threads may be in their pings waiting for confirms that cannot happen.|
||A fix for the above under certain conditions. A wait and two notifys are added.|