Class ThreadEx<V>
java.lang.Object
java.lang.Thread
com.pnfsoftware.jeb.util.concurrent.ThreadEx<V>
- Type Parameters:
V
-
- All Implemented Interfaces:
Runnable
An extension of
Thread
supporting the execution of Callable
as well as
Runnable
. Two additional get()
and get(timeout)
methods, not
unlike Future
's get(), allow querying and waiting for the execution result. When
executing a Runnable, get() will always return null. An exception occurring during the execution
of the thread is collected and re-thrown inside an ExecutionException
object.-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Constructor Details
-
ThreadEx
-
ThreadEx
-
-
Method Details
-
run
public final void run() -
get
Waits if necessary for the computation to complete, and then retrieves its result.- Returns:
- the computed result; always null for a
Runnable
- Throws:
ExecutionException
- if the computation threw an exceptionInterruptedException
- if the current thread was interrupted while waiting
-
get
Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.- Parameters:
millis
- the maximum time to wait, in milliseconds; 0 means wait forever- Returns:
- the computed result; always null for a
Runnable
- Throws:
ExecutionException
- if the computation threw an exceptionInterruptedException
- if the current thread was interrupted while waitingTimeoutException
- if the wait timed out
-