Package org.jbrew.concurrent
Class MethodBlockingTask<T>
java.lang.Object
org.jbrew.concurrent.AbstractTask<T>
org.jbrew.concurrent.RetrievableTask<T>
org.jbrew.concurrent.MethodBlockingTask<T>
- Type Parameters:
T
- The Java Generic of type "T" is explicitly defined at compile-time.
Example:
public class Implementor<T> extends MethodBlockingTask<ConcreteClass>{ }
- All Implemented Interfaces:
java.lang.Runnable
,Task<T>
public abstract class MethodBlockingTask<T> extends RetrievableTask<T>
A
MethodBlockingTask
blocks retrieve()
until the execute()
method has fully completed and terminated.- Author:
- nealk
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description protected
MethodBlockingTask()
-
Method Summary
Modifier and Type Method Description protected void
accept(T obj)
Sets the value of theobj
in aThreadSafe
manner.protected abstract void
execute()
The execute() method allows clients to execute the business logic associated with the respectiveTask
.T
retrieve()
Returns the value of the object once theexecute()
method has returned, as set by theaccept(Object)
method.void
run()
Methods inherited from class org.jbrew.concurrent.AbstractTask
getName, getPriority, getThreadId, setName, setPriority
-
Constructor Details
-
MethodBlockingTask
protected MethodBlockingTask()
-
-
Method Details
-
run
public final void run()Description copied from class:AbstractTask
- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classAbstractTask<T>
-
execute
protected abstract void execute()Description copied from class:AbstractTask
The execute() method allows clients to execute the business logic associated with the respectiveTask
.- Specified by:
execute
in classAbstractTask<T>
-
accept
Description copied from class:RetrievableTask
Sets the value of theobj
in aThreadSafe
manner.- Specified by:
accept
in classRetrievableTask<T>
- Parameters:
obj
- The object to set.
-
retrieve
Returns the value of the object once the
execute()
method has returned, as set by theaccept(Object)
method.From the parent document:
Returns the value of the
Please note that Java generics are used for the programmer to explicitly define the Type when extending this class.obj
in aThreadSafe
manner. The method blocks until a condition is met (such as the excute() method returning or theobj
of type <T> being set (via the setVal() method). For more information on the way internal contention is handled, please refer toMethodBlockingTask
andObjectBlockingTask
.
Example:
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".
- Specified by:
retrieve
in classRetrievableTask<T>
- Returns:
- value of obj - with type <T>
- Throws:
java.lang.InterruptedException
- is thrown if the thread is interrupted.
-