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

    Fields inherited from class org.jbrew.concurrent.RetrievableTask

    printThreadIdFlag
  • Constructor Summary

    Constructors 
    Modifier Constructor Description
    protected MethodBlockingTask()  
  • Method Summary

    Modifier and Type Method 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 once the execute() method has returned, as set by the accept(Object) method.
    void run()

    Methods inherited from class org.jbrew.concurrent.AbstractTask

    getName, getPriority, getThreadId, setName, setPriority

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • run

      public final void run()
      Description copied from class: AbstractTask
      Specified by:
      run in interface java.lang.Runnable
      Overrides:
      run in class AbstractTask<T>
    • execute

      protected abstract void execute()
      Description copied from class: AbstractTask
      The execute() method allows clients to execute the business logic associated with the respective Task.
      Specified by:
      execute in class AbstractTask<T>
    • accept

      protected final void accept​(T obj)
      Description copied from class: RetrievableTask
      Sets the value of the obj in a ThreadSafe manner.
      Specified by:
      accept in class RetrievableTask<T>
      Parameters:
      obj - The object to set.
    • retrieve

      public final T retrieve() throws java.lang.InterruptedException

      Returns the value of the object once the execute() method has returned, as set by the 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.

      Please note that Java generics are used for the programmer to explicitly define the Type when extending this class.
        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 class RetrievableTask<T>
      Returns:
      value of obj - with type <T>
      Throws:
      java.lang.InterruptedException - is thrown if the thread is interrupted.