• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Run thread code by event?

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok i'm quite new to Java so i'll try to explain my problem as well as I can
I have a Producer thread and a Consumer thread.. Both of them are started using .start() in the main method.
On the other hand I have a GUI which has two buttons. One of them must be used to increment the shared variable and the other one to decrement it.
I'm looking for a way to make these threads execute when pressing the corresponding button. I tried making them wait() just when they enter the run() method but then when I notify() them (this is done in another class) i get the IllegalMonitor blah blah exception..
Is there any other wise way to do what i'm trying to achieve? The only thing is that it MUST be done with threads.
Anyone remember their first steps in threading? Help!
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must have a lock on the object in order to call notify() on it: - Peter
[This message has been edited by Peter den Haan (edited December 12, 2001).]
 
Iason Dimitrakopoulos
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you
reply
    Bookmark Topic Watch Topic
  • New Topic