@@ -55,13 +55,12 @@ private static final class EvictorThreadFactory implements ThreadFactory {
5555
5656 @ Override
5757 public Thread newThread (final Runnable runnable ) {
58- final Thread thread = new Thread (null , runnable , "commons-pool-evictor" );
58+ final Thread thread = new Thread (runnable , EvictionConfig . THREAD_NAME );
5959 thread .setDaemon (true ); // POOL-363 - Required for applications using Runtime.addShutdownHook().
6060 AccessController .doPrivileged ((PrivilegedAction <Void >) () -> {
6161 thread .setContextClassLoader (EvictorThreadFactory .class .getClassLoader ());
6262 return null ;
6363 });
64-
6564 return thread ;
6665 }
6766 }
@@ -132,7 +131,7 @@ public void run() {
132131 /** Executor instance */
133132 private static ScheduledThreadPoolExecutor executor ; //@GuardedBy("EvictionTimer.class")
134133
135- /** Keys are weak references to tasks , values are runners managed by executor. */
134+ /** Keys are weak references to pools , values are runners managed by executor. */
136135 private static final HashMap <
137136 WeakReference <BaseGenericObjectPool <?>.Evictor >,
138137 WeakRunner <BaseGenericObjectPool <?>.Evictor >> TASK_MAP = new HashMap <>(); // @GuardedBy("EvictionTimer.class")
@@ -175,6 +174,8 @@ static ScheduledThreadPoolExecutor getExecutor() {
175174 }
176175
177176 /**
177+ * Gets the number of eviction tasks under management.
178+ *
178179 * @return the number of eviction tasks under management.
179180 */
180181 static synchronized int getNumTasks () {
@@ -191,7 +192,7 @@ static HashMap<WeakReference<BaseGenericObjectPool<?>.Evictor>, WeakRunner<BaseG
191192 }
192193
193194 /**
194- * Removes evictor from the task set and executor.
195+ * Removes an evictor from the task set and executor.
195196 * Only called when holding the class lock.
196197 *
197198 * @param evictor Eviction task to remove
@@ -213,22 +214,20 @@ private static void remove(final BaseGenericObjectPool<?>.Evictor evictor) {
213214 * to cancel the task to prevent memory and/or thread leaks in application
214215 * server environments.
215216 *
216- * @param task Task to be scheduled.
217+ * @param pool Task to be scheduled.
217218 * @param delay Duration before task is executed.
218219 * @param period Duration between executions.
219220 */
220- static synchronized void schedule (
221- final BaseGenericObjectPool <?>.Evictor task , final Duration delay , final Duration period ) {
221+ static synchronized void schedule (final BaseGenericObjectPool <?>.Evictor pool , final Duration delay , final Duration period ) {
222222 if (null == executor ) {
223223 executor = new ScheduledThreadPoolExecutor (1 , new EvictorThreadFactory ());
224224 executor .setRemoveOnCancelPolicy (true );
225225 executor .scheduleAtFixedRate (new Reaper (), delay .toMillis (), period .toMillis (), TimeUnit .MILLISECONDS );
226226 }
227- final WeakReference <BaseGenericObjectPool <?>.Evictor > ref = new WeakReference <>(task );
227+ final WeakReference <BaseGenericObjectPool <?>.Evictor > ref = new WeakReference <>(pool );
228228 final WeakRunner <BaseGenericObjectPool <?>.Evictor > runner = new WeakRunner <>(ref );
229- final ScheduledFuture <?> scheduledFuture = executor .scheduleWithFixedDelay (runner , delay .toMillis (),
230- period .toMillis (), TimeUnit .MILLISECONDS );
231- task .setScheduledFuture (scheduledFuture );
229+ final ScheduledFuture <?> scheduledFuture = executor .scheduleWithFixedDelay (runner , delay .toMillis (), period .toMillis (), TimeUnit .MILLISECONDS );
230+ pool .setScheduledFuture (scheduledFuture );
232231 TASK_MAP .put (ref , runner );
233232 }
234233
@@ -242,9 +241,7 @@ private EvictionTimer() {
242241 */
243242 @ Override
244243 public String toString () {
245- final StringBuilder builder = new StringBuilder ();
246- builder .append ("EvictionTimer []" );
247- return builder .toString ();
244+ return "EvictionTimer []" ;
248245 }
249246
250247}
0 commit comments