K
- the type of keys maintained by this mapV
- the type of mapped valuespublic class SingleThreadEvictionScheduler<K,V> extends AbstractQueueEvictionScheduler<K,V>
AbstractQueueEvictionScheduler
which
uses a single thread to manage the automated eviction. The thread waits until
the next scheduled eviction time before trying to perform an automated
eviction. It is notified appropriately each time an entry is added or removed
from the queue to ensure that it will always wake-up at the time of the next
scheduled eviction, not sooner or later. If the queue is empty, the thread is
waiting until notified when an entry is added. The behavior is similar to
that of DelayedTaskEvictionScheduler
, but it is implemented at a
lower level, using a specially crafted thread rather than a scheduled
executor service.Constructor and Description |
---|
SingleThreadEvictionScheduler()
Creates a single thread eviction scheduler with the default queue
implementation (see
AbstractQueueEvictionScheduler ). |
SingleThreadEvictionScheduler(EvictionQueue<K,V> queue)
Creates a single thread eviction scheduler with the specified queue.
|
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 SingleThreadEvictionScheduler()
AbstractQueueEvictionScheduler
). This
constructor starts the eviction thread, which will remain active until
the shutdown method is called.public SingleThreadEvictionScheduler(EvictionQueue<K,V> queue)
queue
- the queue to be usedNullPointerException
- if the queue 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 causes the eviction thread to terminate.
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 notifies the eviction thread, causing it to wake-up and recalculate its waiting time.
onScheduleEviction
in class AbstractQueueEvictionScheduler<K,V>
e
- the entry for which the eviction should be scheduledprotected 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 notifies the eviction thread, causing it to wake-up and recalculate its waiting time.
onCancelEviction
in class AbstractQueueEvictionScheduler<K,V>
e
- the entry for which the eviction should be cancelledprotected void onEvictEntries()
This implementation does nothing.
onEvictEntries
in class AbstractQueueEvictionScheduler<K,V>
Copyright © 2012–2016. All rights reserved.