what about wait or sleep for certain amount of time?
Causes the currently executing thread object to temporarily pause and allow other threads to execute.
quote:
--------------------------------------------------------------------------------
what about wait or sleep for certain amount of time?
--------------------------------------------------------------------------------
If a thread invokes wait(int), sleep(int) or join(int), we expect the thread to block (stop executing). However, if the interruption status is true prior to any one of these 3 methods being called, the thread appears to return immediately. I don't think the thread stops executing.
code:
--------------------------------------------------------------------------------
class Test extends Thread { public void run() { interrupt(); //interrupt myself synchronized(this) { try { System.out.println("isInterrupted = " + isInterrupted()); System.out.println("wait " + System.currentTimeMillis()); wait(5000); } catch (InterruptedException e) { System.out.println("catch " + System.currentTimeMillis()); } } } public static void main(String[] args) { new Test().start(); }}isInterrupted = truewait 1061329071606catch 1061329071606
Wanna see my flashlight? How about this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|