public abstract class EnhancedTimerTask extends Object implements Comparable<EnhancedTimerTask>, Runnable, Computable
Subclasses implement the Periodicity, if needed. Two TimerTasks are compared
with their name and next execution time.
Note: Use compute() method to write the business logic.
| Constructor and Description |
|---|
EnhancedTimerTask()
Constructor for subclasses.
|
EnhancedTimerTask(String name)
Constructor for subclasses.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Cancels this
TimerTask. |
int |
compareTo(EnhancedTimerTask other)
Compares 2 TimeTasks by comparing their next execution times.
|
abstract void |
compute()
Computes the business logic based on the request of subclasses.
|
long |
getElapsedTime()
Gets the elapsed time.
|
Object |
getEvent()
Gets the event.
|
String |
getName()
Gets the name.
|
long |
getNextExecutionTime()
Returns the next time at which the task will be executed, ie the.
|
int |
getNoOfExecTimes()
Gets the no of exec times.
|
int |
getNoOfPendingTimes()
Gets the no of pending times.
|
int |
getNoOfTimes()
Gets the no of times that executes this particular task.
|
long |
getPeriod()
Returns the period of this task.
|
long |
getPrevExecutionTime()
Gets the prev execution time.
|
void |
incrementNoOfExecTimes()
Increments the no of exec times.
|
boolean |
isCanceled()
Returns whether this task is canceled.
|
boolean |
isDaemon()
Checks if is daemon.
|
boolean |
isExecuteImmediatelySet()
Checks if this is set for immediate execution.
|
boolean |
isExpired()
Checks if is expired.
|
boolean |
isFinished()
Returns whether this task is finished.
|
boolean |
isPeriodic()
Returns whether this task is periodic.
|
boolean |
isRunning()
Checks if this is already in execution.
|
boolean |
isSingleExecutable()
Checks if is single executable.
|
void |
run()
This method implementing is not advised, consider implementing
compute() method. |
void |
setDaemon(boolean isDaemon)
Sets the daemon.
|
void |
setEvent(Object event)
Sets the event.
|
void |
setExecuteImmediately(boolean executeImmediately)
Sets this flag if something happens and needs to execute this immediately
rather waiting till the interval expires.
|
void |
setExpired(boolean isExpired)
Sets the expired.
|
void |
setNoOfTimes(int noOfTimes)
Sets the no of times to execute this particular task.
|
void |
setPeriod(long period)
Sets the period.
|
void |
setPeriodic(boolean isPeriodic)
Sets the periodic.
|
void |
setPrevExecutionTime(long prevExecutionTime)
Sets the prev execution time.
|
void |
setRunning(boolean running)
Sets this flag to avoid duplicate execution of this in case of the
primary execution takes much time than expected.
|
void |
setSingleExecutable(boolean singleExecutable)
Sets the single executable to enable single execution of this instance at
any time.
|
String |
toString() |
void |
updateNextExecutionTime()
Sets the next execution time.
|
public EnhancedTimerTask()
public EnhancedTimerTask(String name)
name - the namepublic abstract void compute()
throws ComputingException
Computablecompute in interface ComputableComputingException - the computing exceptionpublic void run()
compute() method.public void setPeriodic(boolean isPeriodic)
isPeriodic - the isPeriodic to setpublic boolean isPeriodic()
getPeriod()public void setPeriod(long period)
period - the period to setpublic long getPeriod()
isPeriodicpublic long getNextExecutionTime()
run() method is called.updateNextExecutionTime()public void updateNextExecutionTime()
getNextExecutionTime()public boolean isFinished()
setFinished(boolean)public boolean isExpired()
public void setExpired(boolean isExpired)
isExpired - the isExpired to setpublic boolean isCanceled()
cancel()public void cancel()
TimerTask.public int compareTo(EnhancedTimerTask other)
compareTo in interface Comparable<EnhancedTimerTask>other - the othergetNextExecutionTime()public void setEvent(Object event)
event - the event to setpublic Object getEvent()
public void setPrevExecutionTime(long prevExecutionTime)
prevExecutionTime - the prevExecutionTime to setpublic long getPrevExecutionTime()
public void setNoOfTimes(int noOfTimes)
noOfTimes - the noOfTimes to setpublic int getNoOfTimes()
public int getNoOfPendingTimes()
public void incrementNoOfExecTimes()
public int getNoOfExecTimes()
public long getElapsedTime()
public boolean isDaemon()
public void setDaemon(boolean isDaemon)
isDaemon - the isDaemon to setpublic String getName()
public void setExecuteImmediately(boolean executeImmediately)
GlobalThread will run this as soon as it has
free worker threads.executeImmediately - the executeImmediately to setisExecuteImmediatelySet()public boolean isExecuteImmediatelySet()
public void setRunning(boolean running)
running - the running to setisRunning()public boolean isRunning()
public void setSingleExecutable(boolean singleExecutable)
singleExecutable - the singleExecutable to setpublic boolean isSingleExecutable()
Copyright © 2016 utils4j. All Rights Reserved.