public class ArrayHeapTimerQueue extends TimerService
Entry.nextRefreshTime field.
Earlier implementations used Timer which has some
disadvantages: per cache entry two additional objects are created,
the task and the lock object. Per one timer a thread is needed. To
insert a timer task with exact time value a java.util.Date object is
needed. A purge/cleanup of cancelled tasks is not done automatically.
In situations with scarce memory, a lot of evictions may occur, which
causes a lot of timer cancellations. This is the reason why this timer implementation
does a purge of cancelled tasks automatically in a regular interval.
During the purge is done, timer events still can run in parallel. Only the
new timer events will be held up until the purge ist finished.
Remark: Yes, this class is a little over engineered. After three make
overs it finally works as expected...TimerService.CancelHandle| Constructor and Description |
|---|
ArrayHeapTimerQueue(String _threadName) |
| Modifier and Type | Method and Description |
|---|---|
NoPayloadTask |
add(TimerListener _listener,
long _fireTime)
Add a timer that fires at the specified time.
|
<T> PayloadTask<T> |
add(TimerPayloadListener<T> _listener,
T _payload,
long _fireTime) |
long |
getCancelCount() |
long |
getEventsDelivered() |
long |
getEventsScheduled() |
long |
getFireExceptionCount() |
long |
getPurgeCount() |
int |
getQueueSize()
Return the tasks in the timer queue including the cancelled.
|
public ArrayHeapTimerQueue(String _threadName)
public NoPayloadTask add(TimerListener _listener, long _fireTime)
TimerServiceadd in class TimerServicepublic <T> PayloadTask<T> add(TimerPayloadListener<T> _listener, T _payload, long _fireTime)
add in class TimerServicepublic int getQueueSize()
TimerServicegetQueueSize in class TimerServicepublic long getEventsDelivered()
getEventsDelivered in class TimerServicepublic long getPurgeCount()
getPurgeCount in class TimerServicepublic long getEventsScheduled()
getEventsScheduled in class TimerServicepublic long getCancelCount()
getCancelCount in class TimerServicepublic long getFireExceptionCount()
getFireExceptionCount in class TimerServicecache2k API documentation. Copyright © 2000–2015 headissue GmbH, Munich.