• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Issue with wait/notify

 
Ranch Hand
Posts: 462
Scala jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23923
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 462
Scala jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Henry, I knew it was something dumb!
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic