Class BackgroundTask

java.lang.Object
org.monte.media.swing.BackgroundTask
All Implemented Interfaces:
Runnable

public abstract class BackgroundTask extends Object implements Runnable
This is an abstract class that you can subclass to perform GUI-related work in a dedicated event dispatcher.

This class is similar to SwingWorker but less complex.

Author:
Werner Randelshofer
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract void
    Compute the value to be returned by the get method.
    protected void
    Called on the event dispatching thread (not on the worker thread) after the construct method has returned without throwing an error.
    protected void
    Called on the event dispatching thread (not on the worker thread) after the construct method has thrown an error.
    protected void
    Called on the event dispatching thread (not on the worker thread) after the construct method has finished and after done() or failed() has been invoked.
    protected Throwable
    Get the error produced by the worker thread, or null if it hasn't thrown one.
    final void
    run()
    Calls #construct on the current thread and invokes #done on the AWT event dispatcher thread.
    void
    Starts the Worker on an internal worker thread.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BackgroundTask

      public BackgroundTask()
  • Method Details

    • run

      public final void run()
      Calls #construct on the current thread and invokes #done on the AWT event dispatcher thread.
      Specified by:
      run in interface Runnable
    • construct

      protected abstract void construct() throws Exception
      Compute the value to be returned by the get method.
      Throws:
      Exception
    • done

      protected void done()
      Called on the event dispatching thread (not on the worker thread) after the construct method has returned without throwing an error.

      The default implementation does nothing. Subclasses may override this method to perform done actions on the Event Dispatch Thread.

    • failed

      protected void failed(Throwable error)
      Called on the event dispatching thread (not on the worker thread) after the construct method has thrown an error.

      The default implementation prints a stack trace. Subclasses may override this method to perform failure actions on the Event Dispatch Thread.

      Parameters:
      error - The error thrown by construct.
    • finished

      protected void finished()
      Called on the event dispatching thread (not on the worker thread) after the construct method has finished and after done() or failed() has been invoked.

      The default implementation does nothing. Subclasses may override this method to perform completion actions on the Event Dispatch Thread.

    • getError

      protected Throwable getError()
      Get the error produced by the worker thread, or null if it hasn't thrown one.
    • start

      public void start()
      Starts the Worker on an internal worker thread.