T
- - The type of object the programmer wishes to operate upon.public abstract class RetrievableTask<T> extends AbstractTask<T>
AbstractTask
that returns a result. Implementors must define a single method
with no arguments called execute
. In these manners, a RetrievableTask
is similar to a
BasicTask
and Callable
in that the former is designed
for classes whose instances can be potentially wrapped in another thread - while the latter also returns a result.
Unlike a Callable
however, a RetrievableTask
does not natively
throw an exception, although certain flagship methods may, such as retrieve()
.
AbstractTask
, please refer to
BasicTask
.AbstractTask
,
ObjectBlockingTask
,
MethodBlockingTask
,
BasicTask
Modifier and Type | Field and Description |
---|---|
protected boolean |
printThreadIdFlag |
Modifier | Constructor and Description |
---|---|
protected |
RetrievableTask()
The default, noargs constructor for RetrievableTask.
|
protected |
RetrievableTask(boolean printThreadIdFlag)
This constructor takes a boolean argument to determine whether the thread number should be printed to the console.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
accept(T obj)
Sets the value of the
obj in a ThreadSafe manner. |
abstract T |
retrieve()
Returns the value of the
obj in a ThreadSafe manner. |
execute, getName, getPriority, getThreadId, run, setName, setPriority
protected RetrievableTask()
protected RetrievableTask(boolean printThreadIdFlag)
This constructor takes a boolean argument to determine whether the thread number should be printed to the console.
A RetrievableTask
can be wrapped inside of a Thread
and executed in the same manner as a Callable
.
printThreadIdFlag
- - boolean
flag which specifies whether thread number should be printed to the console.protected abstract void accept(T obj)
obj
in a ThreadSafe
manner.obj
- The object to set.public abstract T retrieve() throws InterruptedException
Returns the value of the obj
in a ThreadSafe
manner. The method blocks until a condition is
met (such as the excute() method returning or the obj
of type <T> being set (via the setVal()
method). For more information on the way internal contention is handled, please refer to
MethodBlockingTask
and ObjectBlockingTask
.
public class TaskImplementor<T> implements Task<ConcreteClass>{ }
InterruptedException
- is thrown if the thread is interrupted.ObjectBlockingTask
,
MethodBlockingTask
Copyright © 2020. All rights reserved.