K
- the type of keys maintained by this mapV
- the type of mapped valuespublic class RegularTaskEvictionScheduler<K,V> extends AbstractQueueEvictionScheduler<K,V>
AbstractQueueEvictionScheduler
which
uses a single regular task scheduled in an
ScheduledExecutorService
to manage the automated
eviction. The task is scheduled with a fixed delay, independently of the time
of the next scheduled eviction. If the queue is empty, the task is cancelled
until an entry is added.Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_DELAY |
static int |
DEFAULT_THREAD_POOL_SIZE |
static TimeUnit |
DEFAULT_TIME_UNIT |
Constructor and Description |
---|
RegularTaskEvictionScheduler()
Creates a regular task eviction scheduler with the default queue
implementation (see
AbstractQueueEvictionScheduler ), a
ScheduledThreadPoolExecutor , and a default
delay of 1 millisecond. |
RegularTaskEvictionScheduler(EvictionQueue<K,V> queue)
Creates a regular task eviction scheduler with the specified queue, a
ScheduledThreadPoolExecutor , and a default
delay of 1 millisecond. |
RegularTaskEvictionScheduler(EvictionQueue<K,V> queue,
ScheduledExecutorService ses,
long delay,
TimeUnit timeUnit)
Creates a regular task eviction scheduler with the specified queue,
scheduled executor service, and delay.
|
RegularTaskEvictionScheduler(long delay,
TimeUnit timeUnit)
Creates a regular task eviction scheduler with the default queue
implementation (see
AbstractQueueEvictionScheduler ), a
ScheduledThreadPoolExecutor , and the
specified delay. |
RegularTaskEvictionScheduler(ScheduledExecutorService executorService,
long delay,
TimeUnit timeUnit)
Creates a regular task eviction scheduler with the default queue
implementation (see
AbstractQueueEvictionScheduler ) and the
specified scheduled executor service and delay. |
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 static final long DEFAULT_DELAY
public static final TimeUnit DEFAULT_TIME_UNIT
public RegularTaskEvictionScheduler()
AbstractQueueEvictionScheduler
), a
ScheduledThreadPoolExecutor
, and a default
delay of 1 millisecond.public RegularTaskEvictionScheduler(long delay, TimeUnit timeUnit)
AbstractQueueEvictionScheduler
), a
ScheduledThreadPoolExecutor
, and the
specified delay.delay
- the delay between the termination of one execution and the
commencement of the nexttimeUnit
- the time unit of the delay parameterIllegalArgumentException
- if delay is less than or equal to zeropublic RegularTaskEvictionScheduler(ScheduledExecutorService executorService, long delay, TimeUnit timeUnit)
AbstractQueueEvictionScheduler
) and the
specified scheduled executor service and delay.executorService
- the scheduled executor service to be useddelay
- the delay between the termination of one execution and the
commencement of the nexttimeUnit
- the time unit of the delay parameterNullPointerException
- if the scheduled executor service is nullIllegalArgumentException
- if delay is less than or equal to zeropublic RegularTaskEvictionScheduler(EvictionQueue<K,V> queue)
ScheduledThreadPoolExecutor
, and a default
delay of 1 millisecond.queue
- the queue to be usedpublic RegularTaskEvictionScheduler(EvictionQueue<K,V> queue, ScheduledExecutorService ses, long delay, TimeUnit timeUnit)
queue
- the queue to be usedses
- the scheduled executor service to be useddelay
- the delay between the termination of one execution and the
commencement of the nexttimeUnit
- the time unit of the delay parameterNullPointerException
- if either the queue or the scheduled executor service is nullIllegalArgumentException
- if delay is less than or equal to zeropublic 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 executor has scheduled evictions and the current state of the task is not active, and if so schedules the regular 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 executor does not have scheduled evictions and the current state of the task is active, and if so cancels the regular task.
onCancelEviction
in class AbstractQueueEvictionScheduler<K,V>
e
- the entry for which the eviction should be cancelledprotected void onEvictEntries()
This implementation checks if the executor does not have scheduled evictions and the current state of the task is active, and if so cancels the regular task.
onEvictEntries
in class AbstractQueueEvictionScheduler<K,V>
Copyright © 2012–2016. All rights reserved.