Package org.jtrim2.ui.concurrent
Interface BackgroundTask
public interface BackgroundTask
Defines a task which may take long time and is to be executed in the
background. This task is intended to be used in GUI applications
and be executed by a
BackgroundTaskExecutor.
The task is to be executed in the context of an
access token
(BackgroundTaskExecutor automatically does so). The task will have
a chance to report its progress (or anything else) on the UI thread of the associated
UI framework. This reports are also executed in the
context of the same access token in which the task is being executed.
Thread safety
The thread safety property ofBackgroundTask is completely
implementation dependent and the submitter of the task must consider it when
submitting it.
Synchronization transparency
BackgroundTask is not required to be
synchronization transparent. The execute method of this class
should not be executed on the EDT as it can be lengthy.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidexecute(CancellationToken cancelToken, UiReporter reporter) Executes the implementation dependent task of thisBackgroundTask.
-
Method Details
-
execute
Executes the implementation dependent task of thisBackgroundTask. This method may possibly be lengthy and in general must not be executed on the EDT (so that it may not prevent events to processed).- Parameters:
cancelToken- theCancellationTokenwhich can be checked periodically by this task to detect cancellation requests. This argument cannot benull.reporter- the object which can be used to report the progress of the execution of this task (or possibly anything else). This argument cannot benull.- Throws:
OperationCanceledException- thrown if cancellation has been requested and this method did not complete due to this requestException- thrown if there was an error while executing this task. Note that regardless, you should only throw truly unexpected exceptions because you probably need to report such exceptions to the user.
-