I\'m learning about deadlocks in Java, and there\'s this sample code from Sun\'s official tutorial:
Alphonse and Gaston are friends, and great belie
To add to simonn, et al.,
If you would like to visualize this, compile and run the program and generate a thread dump of the running program. You can do this by typing a Ctrl-Break to a Windows console or issueing a kill -QUIT [pid]
command to a *nix system. What this will provide you is a list of all of the Threads
running in your system and where they are either running or waiting, as well as the monitors the threads are either locking on or waiting to lock on.
If you change your Thread names in their constructors, you will have an easier time finding them in the full thread dump:
new Thread(new Runnable() {
public void run() { alphonse.bow(gaston); }
}, "Alphonse").start();
new Thread(new Runnable() {
public void run() { gaston.bow(alphonse); }
}, "Gaston").start();