| java.lang.Object org.openide.util.Task
All known Subclasses: org.openide.loaders.FolderInstance, org.openide.execution.ExecutorTask, org.openide.awt.AWTTask,
Task | public class Task extends Object implements Runnable(Code) | | A task that may be executed in a separate thread and permits examination of its status.
Other threads can check if it is finished or wait for it
to finish.
For example:
Runnable r = new Runnable () {
public void run () {
// do something
}
};
Task task = new Task (r);
RequestProcessor.postRequest (task);
In a different thread one can then test task.isFinished ()
or wait for it with task.waitFinished () .
author: Jaroslav Tulach |
Constructor Summary | |
public | Task(Runnable run) Create a new task. | protected | Task() Constructor for subclasses that wants to control whole execution
itself. |
EMPTY | final public static Task EMPTY(Code) | | Dummy task which is already finished.
|
Task | public Task(Runnable run)(Code) | | Create a new task.
The runnable should provide its own error-handling, as
by default thrown exceptions are simply logged and not rethrown.
Parameters: run - runnable to run that computes the task |
Task | protected Task()(Code) | | Constructor for subclasses that wants to control whole execution
itself.
since: 1.5 |
addTaskListener | public synchronized void addTaskListener(TaskListener l)(Code) | | Add a listener to the task.
Parameters: l - the listener to add |
debug | String debug()(Code) | | Reveal the identity of the worker runnable.
Used for debugging from RequestProcessor.
|
isFinished | final public boolean isFinished()(Code) | | Test whether the task has finished running.
true if so |
notifyFinished | final protected void notifyFinished()(Code) | | Notify all waiters that this task has finished.
See Also: Task.run |
notifyRunning | final protected void notifyRunning()(Code) | | Changes the state of the task to be running. Any call after this
one and before notifyFinished to waitFinished blocks.
since: 1.5 |
removeTaskListener | public synchronized void removeTaskListener(TaskListener l)(Code) | | Remove a listener from the task.
Parameters: l - the listener to remove |
run | public void run()(Code) | | Start the task.
When it finishes (even with an exception) it calls
Task.notifyFinished .
Subclasses may override this method, but they
then need to call
Task.notifyFinished explicitly.
Note that this call runs synchronously, but typically the creator
of the task will call this method in a separate thread.
|
waitFinished | public void waitFinished()(Code) | | Wait until the task is finished.
Changed not to be final in version 1.5
|
waitFinished | public boolean waitFinished(long milliseconds) throws InterruptedException(Code) | | Wait until the task is finished, but only a given time.
Parameters: milliseconds - time in milliseconds to wait for the result exception: InterruptedException - when the waiting has been interrupted true if the task is really finished, or false if the time outhas been exceeded since: 5.0 |
|
|