foxtrot
Class Task

java.lang.Object
  extended by foxtrot.Task
Direct Known Subclasses:
AsyncTask, Job

public abstract class Task
extends Object

A time-consuming task to be executed in the Worker Thread that may throw checked exceptions.
Users must implement the run() method with the time-consuming code, and not worry about exceptions, for example:

 Task task = new Task()
 {
     public Object run() throws InterruptedException
     {
        Thread.sleep(10000);
        return null;
     }
 };
 
Exceptions and Errors thrown by the run() method will be rethrown automatically by Worker.post(Task) or by ConcurrentWorker.post(Task)

Version:
$Revision: 259 $
See Also:
Worker, ConcurrentWorker

Constructor Summary
protected Task()
          Creates a new Task.
 
Method Summary
protected  Object getResultOrThrow()
          Returns the result of this Task operation, as set by setResult(java.lang.Object).
 boolean isCompleted()
          Returns whether the execution of this Task has been completed or not.
abstract  Object run()
          The method to implement with time-consuming code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Task

protected Task()
Creates a new Task.

Method Detail

run

public abstract Object run()
                    throws Exception
The method to implement with time-consuming code. It should NOT be synchronized or synchronize on this Task instance, otherwise the AWT Event Dispatch Thread cannot efficiently test when this Task is completed.

Throws:
Exception

getResultOrThrow

protected final Object getResultOrThrow()
                                 throws Exception
Returns the result of this Task operation, as set by setResult(java.lang.Object). If an exception or an error is thrown by run(), it is rethrown here. Synchronized since the variables are accessed from 2 threads Accessed from the AWT Event Dispatch Thread.

Throws:
Exception
See Also:
setResult(java.lang.Object), setThrowable(java.lang.Throwable)

isCompleted

public final boolean isCompleted()
Returns whether the execution of this Task has been completed or not.



Copyright © 2011 KnowledgePlaza. All Rights Reserved.