|
Oracle Fusion Middleware Java API Reference for Oracle Extension SDK 11g Release 2 (11.1.2.0.0) E17493-01 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object oracle.javatools.parser.util.AsyncTask
public abstract class AsyncTask
The AsyncTask
is a part of a basic API to allow
scheduling asynchronous tasks that support cancelling while the
task is running. It is recommended that JSR 166 be used when
it becomes available as part of the JDK later.
The process of notifying a running task that a cancellation has been requested (and it should abort) is implementation-specific. For example, the following is a possible implementation:
private boolean _isCancelled = false; protected void requestCancelImpl() { _isCancelled = true; } protected boolean isCancelledImpl() { return _isCancelled; }
Within runImpl()
, the implementation could then
call bailIfCancelled()
periodically to bail out
of the task if it has been marked for cancellation. Note, it is
the implementation's responsibility to ensure that any acquired
locks or resources are properly released in case of task
cancellation.
Nested Class Summary | |
---|---|
static class |
AsyncTask.CancelledException
The CancelledException is used to bail out of a
running task. |
Field Summary | |
---|---|
protected static java.lang.String |
CANCELLED_RESULT
Tasks that are cancelled successfully in-progress should return this cancelled result, so that the task status can be updated accordingly. |
static int |
STATUS_CANCELLED
Constant for cancelled status. |
static int |
STATUS_COMPLETED
Constant for completed successfully status. |
static int |
STATUS_FAILED
Constant for completed w/ failed status due to RuntimeException. |
static int |
STATUS_READY
Constant for ready-to-run status. |
static int |
STATUS_RUNNING
Constant for currently running status. |
Constructor Summary | |
---|---|
protected |
AsyncTask()
Set up the AsyncTask in ready-to-run mode. |
Method Summary | |
---|---|
protected void |
bailIfCancelled()
Checks if the task has been marked for cancellation, and throws a CancelledException if it has. |
java.lang.Object |
getResult()
Fetch the completed result of the task (if any). |
int |
getStatus()
Fetches the current status of the task. |
protected abstract boolean |
isCancelledImpl()
Return whether the task is marked for cancellation, to be implemented by the implementation. |
boolean |
isFinished()
Fetch whether this task is completed or not. |
protected void |
requestCancel()
Request to cancel the task. |
protected abstract void |
requestCancelImpl()
Request to cancel the task in-progress, to be implemented by the implementation. |
void |
run()
Performs the task. |
protected abstract java.lang.Object |
runImpl()
Implementation of the task. |
protected static void |
sleep(int ms)
Utility routine to sleep for the given amount of time. |
void |
waitUntilFinished()
Waits until the task is finished (i.e., isFinished() returns true). |
void |
waitUntilFinished(int ms)
Waits until the task is finished (i.e., isFinished() returns true). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int STATUS_READY
public static final int STATUS_RUNNING
public static final int STATUS_COMPLETED
public static final int STATUS_FAILED
public static final int STATUS_CANCELLED
protected static final java.lang.String CANCELLED_RESULT
Constructor Detail |
---|
protected AsyncTask()
Method Detail |
---|
public final int getStatus()
public boolean isFinished()
public void waitUntilFinished()
public void waitUntilFinished(int ms)
ms
- the sleep granularity to useprotected static void sleep(int ms)
ms
- the time in ms to sleeppublic final void run()
run
in interface java.lang.Runnable
protected abstract java.lang.Object runImpl() throws AsyncTask.CancelledException
AsyncTask.CancelledException
- if the task has been cancelledprotected abstract void requestCancelImpl()
protected abstract boolean isCancelledImpl()
protected final void requestCancel()
protected void bailIfCancelled() throws AsyncTask.CancelledException
AsyncTask.CancelledException
- if the task has been marked for cancellationpublic final java.lang.Object getResult()
|
Oracle Fusion Middleware Java API Reference for Oracle Extension SDK 11g Release 2 (11.1.2.0.0) E17493-01 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |