Class CancellationUtil
java.lang.Object
com.complexible.common.cancellation.CancellationUtil
Utility methods for monitoring and cancellation of abstract processes.
- Since:
- 8.2
- Author:
- Pavel Klinov
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidmonitorAsync(Runnable process, Runnable killer, CancelCheck cancelCheck) static <T> TmonitorAsync(Callable<T> process, Runnable killer, CancelCheck cancelCheck) Starts a process in a separate thread and lets it run till canceled.static voidmonitorSync(Runnable process, Runnable killer, CancelCheck cancelCheck) static <T> TmonitorSync(Callable<T> process, Runnable killer, CancelCheck cancelCheck) Starts a process and monitor it from a separate thread.
-
Constructor Details
-
CancellationUtil
public CancellationUtil()
-
-
Method Details
-
monitorAsync
-
monitorAsync
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
-
monitorSync
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.
-