Class AbstractTask<T>

java.lang.Object
org.jbrew.concurrent.AbstractTask<T>
Type Parameters:
T - - The type parameter for the respective AbstractTask.
All Implemented Interfaces:
java.lang.Runnable, Task<T>
Direct Known Subclasses:
BasicTask, RetrievableTask

public abstract class AbstractTask<T>
extends java.lang.Object
implements Task<T>
A ThreadSafe implementation of Task. A AbstractTask wraps boilerplate utility code so its implementors can focus on executing their respective business logic.
Author:
Neal Kumar
  • Constructor Summary

    Constructors 
    Modifier Constructor Description
    protected AbstractTask()
    Default constructor for AbstractTaskblocking which assigns printThreadId to false and the name to the DEFAULT_NAME.
      AbstractTask​(boolean printThreadId)
    A constructor for AbstractTask which includes an option to assign the boolean printThreadId's value.
    protected AbstractTask​(boolean printThreadId, java.lang.String name)
    A constructor for AbstractTask which includes an option to assign the String name's value, as well as the boolean printThreadId's value.
    protected AbstractTask​(java.lang.String name)
    A constructor for AbstractTask which includes an option to assign the String name's value.
  • Method Summary

    Modifier and Type Method Description
    protected abstract void execute()
    The execute() method allows clients to execute the business logic associated with the respective Task.
    java.lang.String getName()  
    int getPriority()  
    long getThreadId()
    Returns the id long of the Task's current thread.
    void run()
    void setName​(java.lang.String name)
    Sets the name of the Task.
    void setPriority​(int priority)  

    Methods inherited from class java.lang.Object

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

    • AbstractTask

      protected AbstractTask()

      Default constructor for AbstractTaskblocking which assigns printThreadId to false and the name to the DEFAULT_NAME. Invoking this constructor will prevent both the name and the current thread's ID from printing to the console.

      Note that this constructor is the most performance-optimal implementation of a AbstractTask.

    • AbstractTask

      public AbstractTask​(boolean printThreadId)

      A constructor for AbstractTask which includes an option to assign the boolean printThreadId's value. Invoking this constructor will assign the name to the DEFAULT_NAME, and prevent the ID from printing to the console.

      Please note that this constructor is the not the most performance-optimal implementation of a AbstractTask. As such, usage of this constructor for performance-sensitive operations is highly discouraged and is considered bad practice. Performance-sensitive applications should instead use the default constructor, AbstractTask().

      Parameters:
      printThreadId - - a boolean flag which indicates whether or not to print out the current thread id to the console.
    • AbstractTask

      protected AbstractTask​(java.lang.String name)

      A constructor for AbstractTask which includes an option to assign the String name's value. Invoking this constructor will prevent the ID from printing to the console.

      Please note that this constructor is the not the most performance-optimal implementation of a AbstractTask. As such, usage of this constructor for performance-sensitive operations is highly discouraged and is considered bad practice. Performance-sensitive applications should instead use the default constructor, AbstractTask().

      Parameters:
      name - - a String for the current Task's name.
    • AbstractTask

      protected AbstractTask​(boolean printThreadId, java.lang.String name)

      A constructor for AbstractTask which includes an option to assign the String name's value, as well as the boolean printThreadId's value. Invoking this constructor will automatically print both the name and ID to the console.

      Please note that this constructor is the not the most performance-optimal implementation of a AbstractTask. As such, usage of this constructor for performance-sensitive operations is highly discouraged and is considered bad practice. Performance-sensitive applications should instead use the default constructor, AbstractTask().

      Parameters:
      printThreadId - - boolean flag which enables console printing of the current thread's ID
      name - - a String for the current Task's name.
  • Method Details

    • run

      public void run()
      Specified by:
      run in interface java.lang.Runnable
    • execute

      protected abstract void execute()
      The execute() method allows clients to execute the business logic associated with the respective Task.
    • getName

      public java.lang.String getName()
      Specified by:
      getName in interface Task<T>
      Returns:
      Returns the String name of the Task.
    • setName

      public final void setName​(java.lang.String name)
      Description copied from interface: Task
      Sets the name of the Task.
      Specified by:
      setName in interface Task<T>
      Parameters:
      name - - the String "name" for the Task.
    • setPriority

      public final void setPriority​(int priority)
      Specified by:
      setPriority in interface Task<T>
    • getPriority

      public final int getPriority()
      Specified by:
      getPriority in interface Task<T>
    • getThreadId

      public long getThreadId()
      Returns the id long of the Task's current thread.
      Specified by:
      getThreadId in interface Task<T>
      Returns:
      Returns the long id of the Task's Thread.