• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Getting a thread to wake up after a notify to called

 
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5634
214
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, that did it!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic