aspose file tools*
The moose likes Threads and Synchronization and the fly likes Issue with wait/notify Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Issue with wait/notify" Watch "Issue with wait/notify" New topic
Author

Issue with wait/notify

Will Myers
Ranch Hand

Joined: Aug 05, 2009
Posts: 313

Hi,
I'm trying to get some code working which should do something like loop through a list of tradeIds and add a value for each trade if it doesn't have one, do nothing if it has been processed, and wait if it is being currently processed then wake up and continue.

My code looks like:

Trade class


the thread:



and the main method class


the problem I'm having is that once a thread goes to sleep it never wakes up, I'm calling notifyAll after a trade is processed but nothing happens. This is probably an embarrasing schoolboy error but I'm stumped!

Thanks
Willy
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18108
    
  39

will myers wrote:
the problem I'm having is that once a thread goes to sleep it never wakes up, I'm calling notifyAll after a trade is processed but nothing happens. This is probably an embarrasing schoolboy error but I'm stumped!


You are using the "this" object for notification, which is the runnable instance for the thread. If you look at your init code, you will see that the three thread have different runnable instances. IOWs, the three threads are using different synchronization and notification objects.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Will Myers
Ranch Hand

Joined: Aug 05, 2009
Posts: 313

Thanks Henry, I knew it was something dumb!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issue with wait/notify
 
Similar Threads
pls suggest me a good style of programming
CoOrd Class
finding closest point
ConcurrentHapMap size not as expected when put done using Multiple Threads
cannot understand the exception in my code,please help