|
|
|
|
|
|
|
|
|
|
|
|
|
|
JAVA PROGRAMMING
Understanding Deadlock Because threads can become blocked and because objects can have synchronized methods that prevent threads from accessing that object until the synchronization lock is released, it's possible for one thread to get stuck waiting for another thread, which in turn waits for another thread, etc., until the chain leads back to a thread waiting on the first one. Thus, there's a continuous loop of threads waiting on each other and no one can move. This is called deadlock. The claim is that it doesn't happen that often, but when it happens to you it's frustrating to debug. There is no language support to help prevent deadlock; it's up to you to avoid it by careful design. These are not comforting words to the person who's trying to debug a deadlocking program. One change that has been made in Java 1.2 to reduce the possibility of deadlock is the deprecation of Thread's stop( ), suspend( ), and resume( ) methods. Here is an example code using Thread's stop( ), suspend( ), resume( ) methods.
|
||||||||
|
|