Class BackgroundTask<T>

  • Type Parameters:
    T - type of object returned by this process
    Direct Known Subclasses:
    URLWorker

    public abstract class BackgroundTask<T>
    extends Object
    This class provides a mechanism for running a task in the background using a separate thread and providing the caller with notification when it has completed.
    • Constructor Detail

      • BackgroundTask

        public BackgroundTask()
    • Method Detail

      • startBackgroundTask

        public final void startBackgroundTask()
        Creates a new thread and begins running the task in the background. When the task has completed, the backgroundTaskCompleted method will be invoked.
      • processBackgroundTask

        public abstract T processBackgroundTask()
                                         throws Throwable
        Performs all processing associated with the task.
        Returns:
        An Object with information about the processing performed for this task, or null if no return value is needed.
        Throws:
        Throwable - throwable that will be passed through the method backgroundTaskCompleted.
      • backgroundTaskCompleted

        public abstract void backgroundTaskCompleted​(T returnValue,
                                                     Throwable throwable)
        This method will be invoked to indicate that the background task has completed. If processing completed successfully, then the Throwable argument will be null and the returnValue argument will contain the value returned by the processBackgroundTask method. If an exception or error was thrown, then the throwable argument will not be null.
        Parameters:
        returnValue - The value returned by the processBackgroundTask method when processing completed, or null if no value was returned or an exception was encountered during processing.
        throwable - A Throwable instance (e.g., an exception) that was raised during processing, or null if all processing completed successfully.