Class CancellationUtil
- java.lang.Object
-
- com.complexible.common.cancellation.CancellationUtil
-
public class CancellationUtil extends java.lang.Object
Utility methods for monitoring and cancellation of abstract processes.- Since:
- 8.2
- Author:
- Pavel Klinov
-
-
Constructor Summary
Constructors Constructor Description CancellationUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
monitorAsync(java.lang.Runnable process, java.lang.Runnable killer, CancelCheck cancelCheck)
static <T> T
monitorAsync(java.util.concurrent.Callable<T> process, java.lang.Runnable killer, CancelCheck cancelCheck)
Starts a process in a separate thread and lets it run till canceled.static void
monitorSync(java.lang.Runnable process, java.lang.Runnable killer, CancelCheck cancelCheck)
static <T> T
monitorSync(java.util.concurrent.Callable<T> process, java.lang.Runnable killer, CancelCheck cancelCheck)
Starts a process and monitor it from a separate thread.
-
-
-
Method Detail
-
monitorAsync
public static void monitorAsync(java.lang.Runnable process, java.lang.Runnable killer, CancelCheck cancelCheck)
-
monitorAsync
public static <T> T monitorAsync(java.util.concurrent.Callable<T> process, java.lang.Runnable killer, CancelCheck cancelCheck)
Starts a process in a separate thread and lets it run till canceled. If the process should be canceled, it runs the kill function but does not wait for the process to actually terminate. If it should wait, usemonitorSync(Callable, Runnable, CancelCheck)
method. If the process is not cancelled, the method returns the value returned by the process function. If the process throws, its exception is propagated.- Type Parameters:
T
- the type of the process return value- Parameters:
process
- the process functionkiller
- the kill function, it will be called only oncecancelCheck
- the cancel check to receive external cancellation signals- Returns:
- the process return value.
-
monitorSync
public static void monitorSync(java.lang.Runnable process, java.lang.Runnable killer, CancelCheck cancelCheck)
-
monitorSync
public static <T> T monitorSync(java.util.concurrent.Callable<T> process, java.lang.Runnable killer, CancelCheck cancelCheck)
Starts a process and monitor it from a separate thread. If the process should be canceled, it runs the kill function and then blocks till the process actually terminates. If it should not wait, usemonitorAsync(Callable, Runnable, CancelCheck)
method. If the process is not cancelled, the method returns the value returned by the process function. If the process throws, its exception is propagated.- Type Parameters:
T
- the type of the process return value- Parameters:
process
- the process functionkiller
- the kill function, it will be called only oncecancelCheck
- the cancel check to receive external cancellation signals- Returns:
- the process return value.
-
-