T
- The Java Generic of type "T" is explicitly defined at compile-time.
public class Implementor<T> extends MethodBlockingTask<ConcreteClass>{ }
public abstract class ObjectBlockingTask<T> extends RetrievableTask<T>
RetrievableTask
allows for the obj
to
be unblocked as soon as the accept(Object)
method has been
called. Leftover logic in the execute()
method will still execute in
a BasicTask
manner. As such, ObjectBlockingTask
provides
fine-grained control for the respective threading operations in downstream
applications.printThreadIdFlag
Constructor and Description |
---|
ObjectBlockingTask() |
Modifier and Type | Method and Description |
---|---|
protected void |
accept(T obj)
Sets the value of the
obj in a ThreadSafe manner. |
protected abstract void |
execute()
The execute() method allows clients to execute the business logic associated
with the respective
Task . |
T |
retrieve()
Returns the value of the object as soon it has been set by the
MethodBlockingTask.accept(Object) method. |
void |
run() |
getName, getPriority, getThreadId, setName, setPriority
public final void run()
AbstractTask
run
in interface Runnable
run
in class AbstractTask<T>
protected abstract void execute()
AbstractTask
Task
.execute
in class AbstractTask<T>
protected final void accept(T obj)
Sets the value of the obj
in a ThreadSafe
manner.
Once this method has been called, the obj
is unblocked
and accessable via the retrieve()
method.
accept
in class RetrievableTask<T>
obj
- The object to set.public final T retrieve() throws InterruptedException
Returns the value of the object as soon it has been set by the
MethodBlockingTask.accept(Object)
method.
From the parent document:
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>{ }
Note that compile-time type checking is enabled. The usage of Java Generics nullifies the compiler warning "unchecked".
retrieve
in class RetrievableTask<T>
InterruptedException
- is thrown if the thread is interrupted.ObjectBlockingTask
,
MethodBlockingTask
Copyright © 2020. All rights reserved.