T
- - The type of the AbstractTask
public abstract class AbstractTask<T> extends Object implements Task<T>
Task
interface,
to minimize the effort required to implement this interface. The programmer should generally provide
a void (no argument) constructor. In general, an AbstractTask
wraps boilerplate utility
code so its implementors can focus on executing their respective business
logic.
AbstractTask
being implemented admits a more efficient implementation.BasicTask
,
RetrievableTask
Modifier | Constructor and Description |
---|---|
protected |
AbstractTask()
Default constructor for
AbstractTask blocking 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,
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(String name)
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
execute()
The execute() method allows clients to execute the business logic associated
with the respective
Task . |
String |
getName() |
int |
getPriority() |
long |
getThreadId()
Returns the id
long of the Task 's current thread. |
void |
run() |
void |
setName(String name)
Sets the name of the
Task . |
void |
setPriority(int priority) |
protected AbstractTask()
Default constructor for AbstractTask
blocking 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
.
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()
.
printThreadId
- - a boolean
flag which indicates whether or
not to print out the current thread id to the console.protected AbstractTask(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()
.
name
- - a String
for the current
Task
's name.protected AbstractTask(boolean printThreadId, 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()
.
printThreadId
- - boolean
flag which enables console
printing of the current thread's IDname
- - a String
for the current
Task
's name.protected abstract void execute()
Task
.public String getName()
public final void setName(String name)
Task
Task
.public final void setPriority(int priority)
setPriority
in interface Task<T>
public final int getPriority()
getPriority
in interface Task<T>
public long getThreadId()
long
of the Task
's current thread.getThreadId
in interface Task<T>
long
id of the Task
's Thread.Copyright © 2020. All rights reserved.