K - the type of keys maintained by this mapV - the type of mapped valuespublic class ExecutorServiceEvictionScheduler<K,V> extends Object implements EvictionScheduler<K,V>
EvictionScheduler which uses a
ScheduledExecutorService to schedule multiple
tasks for entries that should be evicted, one task per entry.| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_THREAD_POOL_SIZE |
| Constructor and Description |
|---|
ExecutorServiceEvictionScheduler()
Creates an eviction scheduler with a
ScheduledThreadPoolExecutor. |
ExecutorServiceEvictionScheduler(ScheduledExecutorService executorService)
Creates an eviction scheduler with the specified scheduled executor
service.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancelEviction(EvictibleEntry<K,V> e)
Cancels the eviction of the specified entry from its map.
|
void |
scheduleEviction(EvictibleEntry<K,V> e)
Schedules the eviction of the specified entry from its map.
|
void |
shutdown()
Immediately shuts down the scheduler and cancels all pending evictions.
|
public static final int DEFAULT_THREAD_POOL_SIZE
public ExecutorServiceEvictionScheduler()
ScheduledThreadPoolExecutor.public ExecutorServiceEvictionScheduler(ScheduledExecutorService executorService)
executorService - the scheduled executor service to be usedNullPointerException - if the scheduled executor service is nullpublic void scheduleEviction(EvictibleEntry<K,V> e)
ConcurrentMapWithTimedEvictionDecorator just after a new entry
has been added. The entry is not guaranteed to be evictible, it may also
be a permanent entry. Therefore, the implementation should check if this
entry is evictible before doing any scheduling.scheduleEviction in interface EvictionScheduler<K,V>e - the entry for which the eviction should be scheduled, if
evictible; it must have been already added to its mappublic void cancelEviction(EvictibleEntry<K,V> e)
ConcurrentMapWithTimedEvictionDecorator just after an entry has
been removed. The entry is not guaranteed to be evictible, it may also be
a permanent entry. Therefore, the implementation should check if this
entry is evictible before doing any cancellation.cancelEviction in interface EvictionScheduler<K,V>e - the entry for which the eviction should be cancelled, if
evictible; it must have been already removed from its mappublic 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.
shutdown in interface EvictionScheduler<K,V>Copyright © 2012–2016. All rights reserved.