Skip to content
Snippets Groups Projects
Commit 97646f8e authored by brinn's avatar brinn
Browse files

change: thread interruption code such that we can give a guarantee that the...

change: thread interruption code such that we can give a guarantee that the ICleaner will not be interrupted

SVN: 7030
parent 8de70060
No related branches found
No related tags found
No related merge requests found
......@@ -183,9 +183,10 @@ public final class TerminableCallable<V> implements Callable<V>, ITerminable
* Note that this method is <i>always</i> called, no matter what the cause is. If you want
* to perform clean up only for some causes, check <var>cause</var> first.
* <p>
* Note that the current Thread may be in an interrupted state when this method is called or
* may get interrupted during the method runs. It is advised not to use methods that throw
* an {@link InterruptedException} or equivalent in this method.
* <i>It is guaranteed that, if the callable is terminated with the
* {@link TerminableCallable#terminate(long)} or the {@link TerminableCallable#terminate()}
* method, this call will be interrupted by neither {@link Thread#interrupt()} nor
* <code>Thread.stop()</code>.</i>
* <p>
* <strong>Don't perform any time consuming operations in this method and avoid any
* operations that can fail with an exception.</strong>
......
......@@ -78,13 +78,14 @@ final class ThreadGuard
}
}
private synchronized Thread getThreadForTermination()
private synchronized Thread tryInterruptAndGetThread()
{
if (state == State.RUNNING)
{
final Thread t = thread;
thread = null;
state = State.TERMINATING;
t.interrupt();
return t;
} else
{
......@@ -159,6 +160,7 @@ final class ThreadGuard
{
state = State.FINISHING;
thread = null;
Thread.interrupted(); // Clear interrupted flag in case we are in mode TERMINATING.
}
/**
......@@ -237,10 +239,9 @@ final class ThreadGuard
return true;
}
final long start = System.currentTimeMillis();
final Thread t = getThreadForTermination();
final Thread t = tryInterruptAndGetThread();
if (t != null)
{
t.interrupt();
if (waitForFinished(waitInterruptMillis))
{
return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment