java.lang.RunnableRequestProcessor.Taskpublic class Task
extends java.lang.Object
implements java.lang.Runnable
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 ().
| Modifier and Type | Field | Description |
|---|---|---|
static Task |
EMPTY |
Dummy task which is already finished.
|
| Modifier | Constructor | Description |
|---|---|---|
protected |
Task() |
Constructor for subclasses that wants to control whole execution
itself.
|
|
Task(java.lang.Runnable run) |
Create a new task.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
addTaskListener(TaskListener l) |
Add a listener to the task.
|
boolean |
isFinished() |
Test whether the task has finished running.
|
protected void |
notifyFinished() |
Notify all waiters that this task has finished.
|
protected void |
notifyRunning() |
Changes the state of the task to be running.
|
void |
removeTaskListener(TaskListener l) |
Remove a listener from the task.
|
void |
run() |
Start the task.
|
java.lang.String |
toString() |
|
void |
waitFinished() |
Wait until the task is finished.
|
boolean |
waitFinished(long milliseconds) |
Wait until the task is finished, but only a given time.
|
public static final Task EMPTY
public Task(java.lang.Runnable run)
run - runnable to run that computes the taskprotected Task()
public final boolean isFinished()
true if sopublic void waitFinished()
final in version 1.5public boolean waitFinished(long milliseconds)
throws java.lang.InterruptedException
milliseconds - time in milliseconds to wait for the resultjava.lang.InterruptedException - when the waiting has been interruptedprotected final void notifyRunning()
protected final void notifyFinished()
runpublic void run()
notifyFinished().
Subclasses may override this method, but they
then need to call notifyFinished() explicitly.
Note that this call runs synchronously, but typically the creator of the task will call this method in a separate thread.
run in interface java.lang.Runnablepublic void addTaskListener(TaskListener l)
isFinished(). In case the task is already finished, the
listener is called immediately.l - the listener to addpublic void removeTaskListener(TaskListener l)
l - the listener to removepublic java.lang.String toString()
toString in class java.lang.ObjectBuilt on April 24 2018. | Portions Copyright 1997-2018 Oracle. All rights reserved.