Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue with wait/notify

 
Will Myers
Ranch Hand
Posts: 381
Java jQuery Scala
  • 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: 21123
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 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: 381
Java jQuery Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry, I knew it was something dumb!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic