File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue with wait/notify

 
Will Myers
Ranch Hand
Posts: 372
Java jQuery Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20817
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Will Myers
Ranch Hand
Posts: 372
Java jQuery Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry, I knew it was something dumb!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic