Package org.apfloat.samples
Class BackgroundOperation<T>
- java.lang.Object
-
- org.apfloat.samples.BackgroundOperation<T>
-
public class BackgroundOperation<T> extends java.lang.ObjectClass for running anOperationin the background in a separate thread. The operation is executed using the ExecutorService retrieved fromApfloatContext.getExecutorService().- Version:
- 1.14.0
-
-
Constructor Summary
Constructors Constructor Description BackgroundOperation(Operation<T> operation)Runs an operation in the background in a separate thread.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()Cancel the operation by interrupting the thread executing it.TgetResult()Get the result of the operation.booleanisFinished()Check if the operation has been completed.
-
-
-
Field Detail
-
future
private java.util.concurrent.Future<T> future
-
-
Method Detail
-
isFinished
public boolean isFinished()
Check if the operation has been completed.- Returns:
trueif the execution of the operation has been completed, otherwisefalse.
-
cancel
public void cancel()
Cancel the operation by interrupting the thread executing it.- Since:
- 1.14.0
-
getResult
public T getResult()
Get the result of the operation. This method blocks until the operation has been completed.- Returns:
- Result of the operation.
- Throws:
java.lang.RuntimeException- If an exception was thrown by the executed operation.
-
-