Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Getting a thread to wake up after a notify to called

 
Sheriff
Posts: 7108
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I am writing a proof-of-concept class to determine how to pause and resume a thread doing a cyclical process in Swing. The idea is to have an instance field called paused that the thread polls.  When the field is true, thread process will call Object.wait() to pause.  Then when the main proccess wants to resume, the paused field is set to false and an Object.notify() is called.

The thread process pauses just fine but when it comes to resuming, it never sees the notify() from the main process. Any help would be welcome.  Below is my code.
 
Bartender
Posts: 4109
156
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this code:

it is uncertain to what this 'this' refers to. But it is not the object that issues the 'notify' later on.

A simple remedy is to have a field Object object. Synchonize twice on this object, do object.wait() and object.notify(), and your code runs fine.
 
Knute Snortum
Sheriff
Posts: 7108
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that did it!
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic