aspose file tools
The moose likes Threads and Synchronization and the fly likes Can't get notify() to work Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Can Watch "Can New topic
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Can't get notify() to work
 
Similar Threads
Lock Mechanism ?
Question about wait() method
invalidMonitorState
Simple wait notify
synchronization and locks