• Post Reply Bookmark Topic Watch Topic
  • New Topic

Run thread code by event?  RSS feed

 
Iason Dimitrakopoulos
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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!
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!