Class 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>
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 forAbstractTask
blocking which assignsprintThreadId
tofalse
and thename
to theDEFAULT_NAME
.AbstractTask(boolean printThreadId)
A constructor forAbstractTask
which includes an option to assign theboolean
printThreadId
's value.protected
AbstractTask(boolean printThreadId, java.lang.String name)
A constructor forAbstractTask
which includes an option to assign theString
name
's value, as well as theboolean
printThreadId
's value.protected
AbstractTask(java.lang.String name)
-
Method Summary
Modifier and Type Method Description protected abstract void
execute()
The execute() method allows clients to execute the business logic associated with the respectiveTask
.java.lang.String
getName()
int
getPriority()
long
getThreadId()
Returns the idlong
of theTask
's current thread.void
run()
void
setName(java.lang.String name)
Sets the name of theTask
.void
setPriority(int priority)
-
Constructor Details
-
AbstractTask
protected AbstractTask()Default constructor for
AbstractTask
blocking which assignsprintThreadId
tofalse
and thename
to theDEFAULT_NAME
. Invoking this constructor will prevent both thename
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 theboolean
printThreadId
's value. Invoking this constructor will assign thename
to theDEFAULT_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
- - aboolean
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 theString
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
- - aString
for the currentTask
's name.
-
AbstractTask
protected AbstractTask(boolean printThreadId, java.lang.String name)A constructor for
AbstractTask
which includes an option to assign theString
name
's value, as well as theboolean
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 IDname
- - aString
for the currentTask
's name.
-
-
Method Details
-
run
public void run()- Specified by:
run
in interfacejava.lang.Runnable
-
execute
protected abstract void execute()The execute() method allows clients to execute the business logic associated with the respectiveTask
. -
getName
public java.lang.String getName() -
setName
public final void setName(java.lang.String name)Description copied from interface:Task
Sets the name of theTask
. -
setPriority
public final void setPriority(int priority)- Specified by:
setPriority
in interfaceTask<T>
-
getPriority
public final int getPriority()- Specified by:
getPriority
in interfaceTask<T>
-
getThreadId
public long getThreadId()Returns the idlong
of theTask
's current thread.- Specified by:
getThreadId
in interfaceTask<T>
- Returns:
- Returns the
long
id of theTask
's Thread.
-