• 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

Notify Thread by a JButton

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
reply
    Bookmark Topic Watch Topic
  • New Topic