The Project        Download   Javadoc   SourceForge   Donate

TaskManager

Uses a Task to be executed in a dedicated thread.

The execute method schedules the task to be executed and returns immediately. The tasks for the same group identifier are queued and executed in order.

The cancel method cancels the running task and all others in the queue

Task

It is the task to be executed.

Containts the following methods:

  1. doInBackground: computes a result. It is executed in a background thread.
  2. done: It is executed on the Event Dispatch Thread if the doInBackground method finish successfully.
  3. canceled: action performed if the task is canceled
  4. handleException: Action performed if the doInBackground, done or canceled method finish with an exception.
  5. setResult and getResult: To transfer the computed result from doInBackground method to done method

Example

 
TaskManager.execute(0, "Waiting...", new Task<Boolean>(){
  @Override
  public void doInBackground() throws Exception {
    Boolean result = ...
    setResult(result);
  }
      
 @Override
  public void done() {
    component.setEnabled(getResult());
  }
});