java - Is Thread.sleep(n) blocking other things from going? Something better to replace it? -


i have little application counting time pressing button,
use thread.sleep() count.

when button pressed, triggers actionlistener class perform thread.run(). thread.sleep() started inside run() function.

//the thread class twentymins implements runnable     @override     public void run() {         try {             thread.sleep(1000*60*20);         } catch (interruptedexception e1) {             e1.printstacktrace();         }     } }  //the actionlistener class reset implements actionlistener {      public static twentymins count = new twentymins();      @override     public void actionperformed(actionevent event) {         count.run();     }  } 

the issue is, button not bounce , able pressed again.
, application can't stopped pressing exit button on jframe.

straightforwardly, think application frozen while thread.sleep() running.

is there better thread.sleep()?

you didn't start background thread here. object can implement runnable (and run method) doesn't make thread. hence when reset button clicked, locks single thread responsible ui.

you need pass runnable object constructor of thread class (java.lang.thread), described in official docs.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -