Package com._1c.g5.v8.dt.common.runtime
Class InterruptingProgressMonitor
java.lang.Object
com._1c.g5.v8.dt.common.runtime.InterruptingProgressMonitor
Bridges Eclipse
IProgressMonitor
with JDK Thread.interrupt()
.
Eclipse assumes that code should synchronously poll IProgressMonitor.isCanceled()
.
However, this is problematic in the following cases:
- Eclipse unaware code does not know anything about
IProgressMonitor
and so cannot poll it. - Code in JDK and most 3rd party libraries knows nothing about
IProgressMonitor
and so cannot poll it. IProgressMonitor
must be passed around through every frame of the stack both in depth and width. If original user-controlledIProgressMonitor
is lost and later replaced with NullProgressMonitor then cancellation ability is lost.
InterruptingProgressMonitor.runInterruptibly(monitor, () -> {
Thread.sleep(10000000);
});
the current thread will fall out of sleep if user cancells job related to the specified monitor.
The implementation starts another daemon thread for the time of execution of the specified code block.
If this new daemon thread detects that the specified monitor has been cancelled then
it interrupts original thread and ends.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionrunInterruptibly
(org.eclipse.core.runtime.IProgressMonitor cancellableMonitor, InterruptingProgressMonitor.InterruptableCode<T, E1, E2> codeToInterrupt) Runs the specified code.
-
Method Details
-
runInterruptibly
public static <T,E1 extends Throwable, T runInterruptiblyE2 extends Throwable> (org.eclipse.core.runtime.IProgressMonitor cancellableMonitor, InterruptingProgressMonitor.InterruptableCode<T, E1, throws E1, E2E2> codeToInterrupt) Runs the specified code. Executes specified code in the current thread. If the specified monitor gets cancelled while the code is still being executed then the current thread is interrupted. If the specified monitor is already cancelled then the code is run anyway and has a chance to react to being eventually interrupted. After the specified code exits, the current thread would not be interrupted anymore when the specified monitor gets cancelled.- Type Parameters:
T
- Type of the value returned by the specified code.E1
- Type of the exception thrown by the specified code.E2
- Type of the exception thrown by the specified code.- Parameters:
cancellableMonitor
- Monitor that user can cancel and thus request the code block to be interrupted. Must not benull
.codeToInterrupt
- The code to be executed. Must not benull
.- Returns:
- The same value as the specified code block returns.
- Throws:
E1
- The same exception as the specified code block throws.E2
- The same exception as the specified code block throws.
-