K
- the type of keys maintained by this mapV
- the type of mapped valuespublic class DelayedTaskEvictionScheduler<K,V> extends AbstractQueueEvictionScheduler<K,V>
AbstractQueueEvictionScheduler
which
uses a single delayed task scheduled in an
ScheduledExecutorService
to manage the automated
eviction. The task is rescheduled appropriately each time an entry is added
or removed from the queue to ensure that it will always fire at the time of
the next scheduled eviction, not sooner or later. If the queue is empty, the
task is cancelled until an entry is added.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_THREAD_POOL_SIZE |
Constructor and Description |
---|
DelayedTaskEvictionScheduler()
Creates a delayed task eviction scheduler with the default queue
implementation (see
AbstractQueueEvictionScheduler ) and a
ScheduledThreadPoolExecutor . |
DelayedTaskEvictionScheduler(EvictionQueue<K,V> queue)
Creates a delayed task eviction scheduler with the specified queue and a
ScheduledThreadPoolExecutor . |
DelayedTaskEvictionScheduler(EvictionQueue<K,V> queue,
ScheduledExecutorService executorService)
Creates a delayed task eviction scheduler with the specified queue and
scheduled executor service.
|
DelayedTaskEvictionScheduler(ScheduledExecutorService ses)
Creates a delayed task eviction scheduler with the default queue
implementation (see
AbstractQueueEvictionScheduler ) and the
specified scheduled executor service. |
Modifier and Type | Method and Description |
---|---|
protected void |
onCancelEviction(EvictibleEntry<K,V> e)
Actually cancels the eviction of the specified entry.
|
protected void |
onEvictEntries()
Performs additional activities upon automated eviction of entries, if
needed.
|
protected void |
onScheduleEviction(EvictibleEntry<K,V> e)
Actually schedules the eviction of the specified entry.
|
void |
shutdown()
Immediately shuts down the scheduler and cancels all pending evictions.
|
cancelEviction, evictEntries, getNextEvictionTime, hasScheduledEvictions, scheduleEviction
public static final int DEFAULT_THREAD_POOL_SIZE
public DelayedTaskEvictionScheduler()
AbstractQueueEvictionScheduler
) and a
ScheduledThreadPoolExecutor
.public DelayedTaskEvictionScheduler(ScheduledExecutorService ses)
AbstractQueueEvictionScheduler
) and the
specified scheduled executor service.ses
- the scheduled executor service to be usedNullPointerException
- if the scheduled executor service is null
public DelayedTaskEvictionScheduler(EvictionQueue<K,V> queue)
ScheduledThreadPoolExecutor
.queue
- the queue to be usedNullPointerException
- if the queue is null
public DelayedTaskEvictionScheduler(EvictionQueue<K,V> queue, ScheduledExecutorService executorService)
queue
- the queue to be usedexecutorService
- the scheduled executor service to be usedNullPointerException
- if either the queue or the scheduled executor service is
null
public void shutdown()
ConcurrentMapWithTimedEvictionDecorator
. Instead, it is intended
to be called by the client that has created the scheduler to properly
shut it down when it's not needed any more.
This implementation simply invokes the shutdownNow method on the scheduled executor service.
protected void onScheduleEviction(EvictibleEntry<K,V> e)
This implementation checks if the current next eviction time is different from the last next eviction time, and if so (re)schedules the task.
onScheduleEviction
in class AbstractQueueEvictionScheduler<K,V>
e
- the entry for which the eviction should be scheduledRejectedExecutionException
- if the task cannot be scheduled for executionprotected void onCancelEviction(EvictibleEntry<K,V> e)
This implementation checks if the current next eviction time is different from the last next eviction time, and if so (re)schedules the task.
onCancelEviction
in class AbstractQueueEvictionScheduler<K,V>
e
- the entry for which the eviction should be cancelledRejectedExecutionException
- if the task cannot be scheduled for executionprotected void onEvictEntries()
This implementation simply always schedules the task.
onEvictEntries
in class AbstractQueueEvictionScheduler<K,V>
RejectedExecutionException
- if the task cannot be scheduled for executionCopyright © 2012–2016. All rights reserved.