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 of BackgroundTask 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 Type
    Method
    Description
    void
    execute(CancellationToken cancelToken, UiReporter reporter)
    Executes the implementation dependent task of this BackgroundTask.
  • Method Details

    • execute

      void execute(CancellationToken cancelToken, UiReporter reporter) throws Exception
      Executes the implementation dependent task of this BackgroundTask. 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 - the CancellationToken which can be checked periodically by this task to detect cancellation requests. This argument cannot be null.
      reporter - the object which can be used to report the progress of the execution of this task (or possibly anything else). This argument cannot be null.
      Throws:
      OperationCanceledException - thrown if cancellation has been requested and this method did not complete due to this request
      Exception - 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.