The other is Threadnot join()yours Threadin the case InterruptedException. join()must wait always or until the call Threadis interrupt()-ed.
, InterruptedException. . :
- . , ,
InterruptedException . ( ?)? - . , , , , Thread ,
InterruptedException. - . , , , , , .
- . ,
Thread ( run()), InterruptedException. - . .
- , Assertion,
InterruptedException , , . - , , ,
InterruptedException.
log() InterruptedException - . , , InterruptedException.
, , . .
public static void joinThread(final Thread thread) {
while (true)
try {
thread.join();
return;
} catch (final InterruptedException e) {
Logger.getGlobal().log(Level.ERROR, "Unexpected InterruptedException", e);
}
}
, .
public static void joinThread(final Thread thread) {
try {
thread.join();
} catch (final InterruptedException e) {
Logger.getGlobal().log(Level.ERROR, "Unexpected InterruptedException", e);
}
}
interrupted.
, , Thread , , InterruptedException, .
public static void joinThread(final Thread thread) {
try {
thread.join();
} catch (final InterruptedException e) {
Logger.getGlobal().log(Level.INFO, "Unexpected InterruptedException, resetting flag", e);
Thread.currentThread().interrupt();
}
}
! , , . , ( Thread s), , interrupted . , , , , InterruptedException, , .
, , , .
public static void joinThread(final Thread thread) throws InterruptedException {
try {
thread.join();
} catch (final InterruptedException e) {
Logger.getGlobal().log(Level.FINE, "Got InterruptedException, propagating it to the caller", e);
throw e;
}
}
- , , .
.
, , - , , .
public static void joinThread(final Thread thread) {
try {
thread.join();
} catch (final InterruptedException e) {
Logger.getGlobal().log(Level.FINE, "Got InterruptedException, handling it", e);
}
}
.
, , Thread.interrupt() ThreadGroup.interrupt() , AssertionError .
.
public static void joinThread(final Thread thread) {
try {
thread.join();
} catch (final InterruptedException e) {
Logger.getGlobal().log(Level.ERROR, "Unexpected InterruptedException", e);
assert false : e;
}
}
public static void joinThread(final Thread thread) {
try {
thread.join();
} catch (final InterruptedException e) {
Logger.getGlobal().log(Level.FATAL, "Unexpected InterruptedException", e);
throw new AssertionError(e, "Unexpected Thread interruption.");
}
}
InterruptedException , , , . , , , .
public static void joinThread(final Thread thread) {
try {
thread.join();
} catch (final InterruptedException e) {
Logger.getGlobal().log(Level.ERROR, "Unexpected InterruptedException", e);
throw new SomeException(e, "Unexpected Thread interruption.");
}
}
, . . 100 Thread.sleep() - - , . , . , Thread.interrupt() SIGHUP, SIGHUP .
, AssertionError. AssertionError - Throwable, Exception, , , - , AssertionError , , , , . , AssertionError , (-) , - , AssertionError UncaughtExceptionHandler Thread s.