Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Notify Thread by a JButton  RSS feed

 
ilumi kinoko
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my problem is how can I use a button to notify a thread in sleep.
I just can't did it.

My code is Like :




Can anyone help me in this issue or can provide other idea to temporary stop at line 57?
Please I really need help, I have work this for 3 days and can't find a solution
Thank you
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ilumi,

There are a lot of problems with your code. A few of the problems include:
1) notify() doesn't 'pair' with Thread.sleep() in any way. You can't notify() a sleeping thread to make it wake up. You use notify() on an Object which another thread is wait()ing on. Or if you really want to use Thread.sleep(), you would interrupt the sleeping thread.

2) In order to notify() you need a reference to the same Object used for wait()ing. If you want to interrupt a sleeping thread you need a reference to the same Thread that is sleeping.

Unfortunately, simply posting code which fixes the problem will not really help you, since it seems you are missing some fundamentals when it comes to Threads, and synchronization. I suggest reading up on Threading in Java. One good place to start is this Tutorial from Oracle: The Java: Concurrency Tutorial. Make sure you read the first few chapters, at least up through 'Guarded Blocks' and really try out the examples until you understand what and how sleep works, how synchronization works, and hopefully can figure out which one you want to use.
 
ilumi kinoko
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Steve, you are so KIND!!!
I look the Tutorial you gave me and find solution in "Guarded Blocks". <<-----I am really grateful for your kindness
But still something strange. I will post today
Since I am a little bit tire, it's 3:11am now in my country
I want to

Thanks AGAIN!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!