Package io.jmix.flowui.backgroundtask
Interface TaskExecutor<T,V>
- Type Parameters:
T- the type of progress updates passed during task executionV- the type of the result produced by the background task
public interface TaskExecutor<T,V>
The TaskExecutor interface provides methods for managing the lifecycle of a background task.
It allows tasks to be started, canceled, tracked for progress, and finalized upon completion.
The interface ensures thread-safe operations and UI integration for updating or interacting
with the user interface during task execution.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanCancels the execution and removes task formBackgroundTaskWatchDogand fromBackgroundTaskManager.Returns the finalizer runnable that is responsible for resource cleanup or post-task actions once the execution of a background task is complete.Joins task thread to current and waits if task is not finished.getTask()voidhandleProgress(T... changes) Handles changes from working thread.booleanChecks whether the background task is currently in progress.booleanChecks whether the background task is cancelled.booleanisDone()Checks whether the background task is completed.voidsetFinalizer(Runnable finalizer) Sets done handler for clear resources.voidExecutes background task.
-
Method Details
-
startExecution
void startExecution()Executes background task. -
cancelExecution
boolean cancelExecution()Cancels the execution and removes task formBackgroundTaskWatchDogand fromBackgroundTaskManager.- Returns:
trueif the canceling was successful
-
getResult
Joins task thread to current and waits if task is not finished.- Returns:
- result of the task
-
getTask
BackgroundTask<T,V> getTask()- Returns:
- the task
-
isCancelled
boolean isCancelled()Checks whether the background task is cancelled.- Returns:
trueif the task is cancelled,falseotherwise.
-
isDone
boolean isDone()Checks whether the background task is completed.- Returns:
trueif the task is finished,falseotherwise.
-
inProgress
boolean inProgress()Checks whether the background task is currently in progress.- Returns:
trueif the task is in progress,falseotherwise.
-
setFinalizer
Sets done handler for clear resources.- Parameters:
finalizer- Runnable handler
-
getFinalizer
Runnable getFinalizer()Returns the finalizer runnable that is responsible for resource cleanup or post-task actions once the execution of a background task is complete.- Returns:
- the finalizer runnable, or
nullif no finalizer has been set
-
handleProgress
Handles changes from working thread.- Parameters:
changes- Changes
-