public abstract class Future
extends java.lang.Thread
Constructor and Description |
---|
Future(java.lang.String threadName,
java.lang.Object lock)
Creates an asynchronous task, but does not run it.
|
Modifier and Type | Method and Description |
---|---|
protected abstract java.lang.Object |
futureExecution()
Define this method to implement the task.
|
java.lang.Object |
futureGet()
Blocks caller until the task is completed, and get its result
or exception.
|
boolean |
isComplete()
Checks if the task is complete.
|
void |
run()
Calls abstract method futureExecution() which is supposed to implement
(through inheritance) the task, and manages synchronization: on return
from futureExecution():
all calls blocked on method futureGet() are resumed
method isComplete() definitely returns true instead of false
when a lock is provided, all threads waiting on this lock are
notified
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public Future(java.lang.String threadName, java.lang.Object lock)
threadName
- an arbitrary convenient name to identify this thread
(for debugging purpose)lock
- an optional lock object to wait on for synchronization with
this task completion. When null, justThread.start()
public final void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public final java.lang.Object futureGet() throws java.lang.Exception
java.lang.Exception
- if the task defined by method futureExecution()
threw an exceptionpublic final boolean isComplete()
protected abstract java.lang.Object futureExecution() throws java.lang.Exception
java.lang.Exception
- the task could not complete.