IllegalMonitorStateException, wait() , synchronized.
try {
synchronized (thread) {
thread.wait(10000);
}
} catch (InterruptedException e) {
System.err.println("interrupted.");
}
thread, , , :
try {
thread.join(10000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
System.err.println("interrupted.");
}
, , , join , (). , thread.isAlive() .
, thread, , 10000 millis, - thread.interrupt(). sleep() wait(), InterruptedException, .
, - :
while (!Thread.currentThread.isInterrupted()) {
// do it thread stuff
}
, , - , , InterruptedException , :
} catch (InterruptedException e) {
Thread.currentThread.interrupt();
System.err.println("interrupted.");
}