| Author |
Can't get notify() to work
|
Jared Folino
Greenhorn
Joined: Apr 27, 2007
Posts: 25
|
|
Basically the problem is that the last print statement "Code Block 4" does not print. This is because the main thread that calls notify() completes before the second thread (Thread-1) begins. As such when Thread-1 is called it permanently blocked as their is no active thread to call notify().
|
 |
Edward Harned
Ranch Hand
Joined: Sep 19, 2005
Posts: 288
|
|
This is because the main thread that calls notify() completes before the second thread (Thread-1) begins. How true. You need to communicate between the threads, back and forth. Read the tutorial and follow the instructions. Concurrency
|
Ed's latest article: A Java Parallel Calamity http://coopsoft.com/ar/Calamity2Article.html
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
See how this variation is different: I narrowed the scope of the synchronized blocks so they only control the wait & notify. Work through what was synchronized in your version and see if that explains your results.
|
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
|
 |
 |
|
|
subject: Can't get notify() to work
|
|
|