View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.pool2.impl;
18  
19  import java.time.Duration;
20  
21  import org.apache.commons.pool2.BaseObject;
22  
23  /**
24   * Provides the implementation for the common attributes shared by the sub-classes. New instances of this class will be created using the defaults defined by
25   * the public constants.
26   * <p>
27   * This class is not thread-safe.
28   * </p>
29   *
30   * @param <T> Type of element pooled.
31   * @since 2.0
32   */
33  public abstract class BaseObjectPoolConfig<T> extends BaseObject implements Cloneable {
34  
35      /**
36       * The default value for the {@code lifo} configuration attribute: {@value}.
37       *
38       * @see GenericObjectPool#getLifo()
39       * @see GenericKeyedObjectPool#getLifo()
40       */
41      public static final boolean DEFAULT_LIFO = true;
42  
43      /**
44       * The default value for the {@code fairness} configuration attribute: {@value}.
45       *
46       * @see GenericObjectPool#getFairness()
47       * @see GenericKeyedObjectPool#getFairness()
48       */
49      public static final boolean DEFAULT_FAIRNESS = false;
50  
51      /**
52       * The default value for the {@code maxWait} configuration attribute: {@value}.
53       *
54       * @see GenericObjectPool#getMaxWaitDuration()
55       * @see GenericKeyedObjectPool#getMaxWaitDuration()
56       * @deprecated Use {@link #DEFAULT_MAX_WAIT}.
57       */
58      @Deprecated
59      public static final long DEFAULT_MAX_WAIT_MILLIS = -1L;
60  
61      /**
62       * The default value for the {@code maxWait} configuration attribute.
63       *
64       * @see GenericObjectPool#getMaxWaitDuration()
65       * @see GenericKeyedObjectPool#getMaxWaitDuration()
66       * @since 2.10.0
67       */
68      public static final Duration DEFAULT_MAX_WAIT = Duration.ofMillis(DEFAULT_MAX_WAIT_MILLIS);
69  
70      /**
71       * The default value for the {@code minEvictableIdleDuration} configuration attribute: {@value}.
72       *
73       * @see GenericObjectPool#getMinEvictableIdleDuration()
74       * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
75       * @deprecated Use {@link #DEFAULT_MIN_EVICTABLE_IDLE_TIME}.
76       */
77      @Deprecated
78      public static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS = 1000L * 60L * 30L;
79  
80      /**
81       * The default value for the {@code minEvictableIdleDuration} configuration attribute.
82       *
83       * @see GenericObjectPool#getMinEvictableIdleDuration()
84       * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
85       * @since 2.11.0
86       */
87      public static final Duration DEFAULT_MIN_EVICTABLE_IDLE_DURATION = Duration.ofMillis(DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
88  
89      /**
90       * The default value for the {@code minEvictableIdleDuration} configuration attribute.
91       *
92       * @see GenericObjectPool#getMinEvictableIdleDuration()
93       * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
94       * @since 2.10.0
95       * @deprecated Use {@link #DEFAULT_MIN_EVICTABLE_IDLE_DURATION}.
96       */
97      @Deprecated
98      public static final Duration DEFAULT_MIN_EVICTABLE_IDLE_TIME = Duration.ofMillis(DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
99  
100     /**
101      * The default value for the {@code softMinEvictableIdleTime} configuration attribute: {@value}.
102      *
103      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
104      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
105      * @deprecated Use {@link #DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME}.
106      */
107     @Deprecated
108     public static final long DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS = -1;
109 
110     /**
111      * The default value for the {@code softMinEvictableIdleTime} configuration attribute.
112      *
113      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
114      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
115      * @since 2.10.0
116      * @deprecated Use {@link #DEFAULT_SOFT_MIN_EVICTABLE_IDLE_DURATION}.
117      */
118     @Deprecated
119     public static final Duration DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME = Duration.ofMillis(DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
120 
121     /**
122      * The default value for the {@code softMinEvictableIdleTime} configuration attribute.
123      *
124      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
125      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
126      * @since 2.11.0
127      */
128     public static final Duration DEFAULT_SOFT_MIN_EVICTABLE_IDLE_DURATION = Duration.ofMillis(DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
129 
130     /**
131      * The default value for {@code evictorShutdownTimeout} configuration attribute: {@value}.
132      *
133      * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
134      * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
135      * @deprecated Use {@link #DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT}.
136      */
137     @Deprecated
138     public static final long DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS = 10L * 1000L;
139 
140     /**
141      * The default value for {@code evictorShutdownTimeout} configuration attribute.
142      *
143      * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
144      * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
145      * @since 2.10.0
146      */
147     public static final Duration DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT = Duration.ofMillis(DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT_MILLIS);
148 
149     /**
150      * The default value for the {@code numTestsPerEvictionRun} configuration attribute: {@value}.
151      *
152      * @see GenericObjectPool#getNumTestsPerEvictionRun()
153      * @see GenericKeyedObjectPool#getNumTestsPerEvictionRun()
154      */
155     public static final int DEFAULT_NUM_TESTS_PER_EVICTION_RUN = 3;
156 
157     /**
158      * The default value for the {@code testOnCreate} configuration attribute: {@value}.
159      *
160      * @see GenericObjectPool#getTestOnCreate()
161      * @see GenericKeyedObjectPool#getTestOnCreate()
162      * @since 2.2
163      */
164     public static final boolean DEFAULT_TEST_ON_CREATE = false;
165 
166     /**
167      * The default value for the {@code testOnBorrow} configuration attribute: {@value}.
168      *
169      * @see GenericObjectPool#getTestOnBorrow()
170      * @see GenericKeyedObjectPool#getTestOnBorrow()
171      */
172     public static final boolean DEFAULT_TEST_ON_BORROW = false;
173 
174     /**
175      * The default value for the {@code testOnReturn} configuration attribute: {@value}.
176      *
177      * @see GenericObjectPool#getTestOnReturn()
178      * @see GenericKeyedObjectPool#getTestOnReturn()
179      */
180     public static final boolean DEFAULT_TEST_ON_RETURN = false;
181 
182     /**
183      * The default value for the {@code testWhileIdle} configuration attribute: {@value}.
184      *
185      * @see GenericObjectPool#getTestWhileIdle()
186      * @see GenericKeyedObjectPool#getTestWhileIdle()
187      */
188     public static final boolean DEFAULT_TEST_WHILE_IDLE = false;
189 
190     /**
191      * The default value for the {@code timeBetweenEvictionRuns} configuration attribute: {@value}.
192      *
193      * @see GenericObjectPool#getDurationBetweenEvictionRuns()
194      * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
195      * @deprecated Use {@link #DEFAULT_TIME_BETWEEN_EVICTION_RUNS}.
196      */
197     @Deprecated
198     public static final long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS = -1L;
199 
200     /**
201      * The default value for the {@code timeBetweenEvictionRuns} configuration attribute.
202      *
203      * @see GenericObjectPool#getDurationBetweenEvictionRuns()
204      * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
205      * @since 2.12.0
206      */
207     public static final Duration DEFAULT_DURATION_BETWEEN_EVICTION_RUNS = Duration.ofMillis(DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
208 
209     /**
210      * The default value for the {@code timeBetweenEvictionRuns} configuration attribute.
211      *
212      * @see GenericObjectPool#getDurationBetweenEvictionRuns()
213      * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
214      * @deprecated Use {@link #DEFAULT_DURATION_BETWEEN_EVICTION_RUNS}.
215      */
216     @Deprecated
217     public static final Duration DEFAULT_TIME_BETWEEN_EVICTION_RUNS = Duration.ofMillis(DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
218 
219     /**
220      * The default value for the {@code blockWhenExhausted} configuration attribute: {@value}.
221      *
222      * @see GenericObjectPool#getBlockWhenExhausted()
223      * @see GenericKeyedObjectPool#getBlockWhenExhausted()
224      */
225     public static final boolean DEFAULT_BLOCK_WHEN_EXHAUSTED = true;
226 
227     /**
228      * The default value for enabling JMX for pools created with a configuration instance: {@value}.
229      */
230     public static final boolean DEFAULT_JMX_ENABLE = true;
231 
232     /**
233      * The default value for the prefix used to name JMX enabled pools created with a configuration instance: {@value}.
234      *
235      * @see GenericObjectPool#getJmxName()
236      * @see GenericKeyedObjectPool#getJmxName()
237      */
238     public static final String DEFAULT_JMX_NAME_PREFIX = "pool";
239 
240     /**
241      * The default value for the base name to use to name JMX enabled pools created with a configuration instance. The default is {@code null} which means the
242      * pool will provide the base name to use.
243      *
244      * @see GenericObjectPool#getJmxName()
245      * @see GenericKeyedObjectPool#getJmxName()
246      */
247     public static final String DEFAULT_JMX_NAME_BASE = null;
248 
249     /**
250      * The default value for the {@code evictionPolicyClassName} configuration attribute.
251      *
252      * @see GenericObjectPool#getEvictionPolicyClassName()
253      * @see GenericKeyedObjectPool#getEvictionPolicyClassName()
254      */
255     public static final String DEFAULT_EVICTION_POLICY_CLASS_NAME = DefaultEvictionPolicy.class.getName();
256 
257     /**
258      * The default value for the {@code collectDetailedStatistics} configuration
259      * attribute. When {@code true}, the pool will collect detailed timing statistics
260      * for monitoring purposes. When {@code false}, detailed statistics collection
261      * is disabled, improving performance under high load.
262      * <p>
263      * This setting affects data collection for mean active time, mean idle time, and mean borrow wait time.
264      * </p>
265      *
266      * @since 2.13.0
267      */
268     public static final boolean DEFAULT_COLLECT_DETAILED_STATISTICS = true;
269 
270     private boolean lifo = DEFAULT_LIFO;
271 
272     private boolean fairness = DEFAULT_FAIRNESS;
273 
274     private Duration maxWaitDuration = DEFAULT_MAX_WAIT;
275 
276     private Duration minEvictableIdleDuration = DEFAULT_MIN_EVICTABLE_IDLE_TIME;
277 
278     private Duration evictorShutdownTimeoutDuration = DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT;
279 
280     private Duration softMinEvictableIdleDuration = DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME;
281 
282     private int numTestsPerEvictionRun = DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
283 
284     private EvictionPolicy<T> evictionPolicy; // Only 2.6.0 applications set this
285 
286     private String evictionPolicyClassName = DEFAULT_EVICTION_POLICY_CLASS_NAME;
287 
288     private boolean testOnCreate = DEFAULT_TEST_ON_CREATE;
289 
290     private boolean testOnBorrow = DEFAULT_TEST_ON_BORROW;
291 
292     private boolean testOnReturn = DEFAULT_TEST_ON_RETURN;
293 
294     private boolean testWhileIdle = DEFAULT_TEST_WHILE_IDLE;
295 
296     private Duration durationBetweenEvictionRuns = DEFAULT_DURATION_BETWEEN_EVICTION_RUNS;
297 
298     private boolean blockWhenExhausted = DEFAULT_BLOCK_WHEN_EXHAUSTED;
299 
300     private boolean jmxEnabled = DEFAULT_JMX_ENABLE;
301 
302     // TODO Consider changing this to a single property for 3.x
303     private String jmxNamePrefix = DEFAULT_JMX_NAME_PREFIX;
304 
305     private String jmxNameBase = DEFAULT_JMX_NAME_BASE;
306 
307     private boolean collectDetailedStatistics = DEFAULT_COLLECT_DETAILED_STATISTICS;
308 
309     /**
310      * Constructs a new instance.
311      */
312     public BaseObjectPoolConfig() {
313         // empty
314     }
315 
316     /**
317      * Gets the value for the {@code blockWhenExhausted} configuration attribute for pools created with this configuration instance.
318      *
319      * @return The current setting of {@code blockWhenExhausted} for this configuration instance
320      * @see GenericObjectPool#getBlockWhenExhausted()
321      * @see GenericKeyedObjectPool#getBlockWhenExhausted()
322      */
323     public boolean getBlockWhenExhausted() {
324         return blockWhenExhausted;
325     }
326 
327     /**
328      * Gets the value for the {@code collectDetailedStatistics} configuration attribute
329      * for pools created with this configuration instance.
330      * <p>
331      * This setting affects data collection for mean active time, mean idle time, and mean borrow wait time.
332      * </p>
333      *
334      * @return  {@code true} if detailed statistics collection is enabled,
335      *          {@code false} if disabled for improved performance.
336      * @see GenericObjectPool#getCollectDetailedStatistics()
337      * @see GenericKeyedObjectPool#getCollectDetailedStatistics()
338      * @since 2.13.0
339      */
340     public boolean getCollectDetailedStatistics() {
341         return collectDetailedStatistics;
342     }
343 
344     /**
345      * Gets the value for the {@code timeBetweenEvictionRuns} configuration attribute for pools created with this configuration instance.
346      *
347      * @return The current setting of {@code timeBetweenEvictionRuns} for this configuration instance
348      * @see GenericObjectPool#getDurationBetweenEvictionRuns()
349      * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
350      * @since 2.11.0
351      */
352     public Duration getDurationBetweenEvictionRuns() {
353         return durationBetweenEvictionRuns;
354     }
355 
356     /**
357      * Gets the value for the {@code evictionPolicyClass} configuration attribute for pools created with this configuration instance.
358      *
359      * @return The current setting of {@code evictionPolicyClass} for this configuration instance
360      * @see GenericObjectPool#getEvictionPolicy()
361      * @see GenericKeyedObjectPool#getEvictionPolicy()
362      * @since 2.6.0
363      */
364     public EvictionPolicy<T> getEvictionPolicy() {
365         return evictionPolicy;
366     }
367 
368     /**
369      * Gets the value for the {@code evictionPolicyClassName} configuration attribute for pools created with this configuration instance.
370      *
371      * @return The current setting of {@code evictionPolicyClassName} for this configuration instance
372      * @see GenericObjectPool#getEvictionPolicyClassName()
373      * @see GenericKeyedObjectPool#getEvictionPolicyClassName()
374      */
375     public String getEvictionPolicyClassName() {
376         return evictionPolicyClassName;
377     }
378 
379     /**
380      * Gets the value for the {@code evictorShutdownTimeout} configuration attribute for pools created with this configuration instance.
381      *
382      * @return The current setting of {@code evictorShutdownTimeout} for this configuration instance
383      * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
384      * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
385      * @since 2.10.0
386      * @deprecated Use {@link #getEvictorShutdownTimeoutDuration()}.
387      */
388     @Deprecated
389     public Duration getEvictorShutdownTimeout() {
390         return evictorShutdownTimeoutDuration;
391     }
392 
393     /**
394      * Gets the value for the {@code evictorShutdownTimeout} configuration attribute for pools created with this configuration instance.
395      *
396      * @return The current setting of {@code evictorShutdownTimeout} for this configuration instance
397      * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
398      * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
399      * @since 2.11.0
400      */
401     public Duration getEvictorShutdownTimeoutDuration() {
402         return evictorShutdownTimeoutDuration;
403     }
404 
405     /**
406      * Gets the value for the {@code evictorShutdownTimeout} configuration attribute for pools created with this configuration instance.
407      *
408      * @return The current setting of {@code evictorShutdownTimeout} for this configuration instance
409      * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
410      * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
411      * @deprecated Use {@link #getEvictorShutdownTimeout()}.
412      */
413     @Deprecated
414     public long getEvictorShutdownTimeoutMillis() {
415         return evictorShutdownTimeoutDuration.toMillis();
416     }
417 
418     /**
419      * Gets the value for the {@code fairness} configuration attribute for pools created with this configuration instance.
420      *
421      * @return The current setting of {@code fairness} for this configuration instance
422      * @see GenericObjectPool#getFairness()
423      * @see GenericKeyedObjectPool#getFairness()
424      */
425     public boolean getFairness() {
426         return fairness;
427     }
428 
429     /**
430      * Gets the value of the flag that determines if JMX will be enabled for pools created with this configuration instance.
431      *
432      * @return The current setting of {@code jmxEnabled} for this configuration instance
433      */
434     public boolean getJmxEnabled() {
435         return jmxEnabled;
436     }
437 
438     /**
439      * Gets the value of the JMX name base that will be used as part of the name assigned to JMX enabled pools created with this configuration instance. A value
440      * of {@code null} means that the pool will define the JMX name base.
441      *
442      * @return The current setting of {@code jmxNameBase} for this configuration instance
443      */
444     public String getJmxNameBase() {
445         return jmxNameBase;
446     }
447 
448     /**
449      * Gets the value of the JMX name prefix that will be used as part of the name assigned to JMX enabled pools created with this configuration instance.
450      *
451      * @return The current setting of {@code jmxNamePrefix} for this configuration instance
452      */
453     public String getJmxNamePrefix() {
454         return jmxNamePrefix;
455     }
456 
457     /**
458      * Gets the value for the {@code lifo} configuration attribute for pools created with this configuration instance.
459      *
460      * @return The current setting of {@code lifo} for this configuration instance
461      * @see GenericObjectPool#getLifo()
462      * @see GenericKeyedObjectPool#getLifo()
463      */
464     public boolean getLifo() {
465         return lifo;
466     }
467 
468     /**
469      * Gets the value for the {@code maxWait} configuration attribute for pools created with this configuration instance.
470      *
471      * @return The current setting of {@code maxWait} for this configuration instance
472      * @see GenericObjectPool#getMaxWaitDuration()
473      * @see GenericKeyedObjectPool#getMaxWaitDuration()
474      * @since 2.11.0
475      */
476     public Duration getMaxWaitDuration() {
477         return maxWaitDuration;
478     }
479 
480     /**
481      * Gets the value for the {@code maxWait} configuration attribute for pools created with this configuration instance.
482      *
483      * @return The current setting of {@code maxWait} for this configuration instance
484      * @see GenericObjectPool#getMaxWaitDuration()
485      * @see GenericKeyedObjectPool#getMaxWaitDuration()
486      * @deprecated Use {@link #getMaxWaitDuration()}.
487      */
488     @Deprecated
489     public long getMaxWaitMillis() {
490         return maxWaitDuration.toMillis();
491     }
492 
493     /**
494      * Gets the value for the {@code minEvictableIdleTime} configuration attribute for pools created with this configuration instance.
495      *
496      * @return The current setting of {@code minEvictableIdleTime} for this configuration instance
497      * @see GenericObjectPool#getMinEvictableIdleDuration()
498      * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
499      * @since 2.11.0
500      */
501     public Duration getMinEvictableIdleDuration() {
502         return minEvictableIdleDuration;
503     }
504 
505     /**
506      * Gets the value for the {@code minEvictableIdleTime} configuration attribute for pools created with this configuration instance.
507      *
508      * @return The current setting of {@code minEvictableIdleTime} for this configuration instance
509      * @see GenericObjectPool#getMinEvictableIdleDuration()
510      * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
511      * @since 2.10.0
512      * @deprecated Use {@link #getMinEvictableIdleDuration()}.
513      */
514     @Deprecated
515     public Duration getMinEvictableIdleTime() {
516         return minEvictableIdleDuration;
517     }
518 
519     /**
520      * Gets the value for the {@code minEvictableIdleTime} configuration attribute for pools created with this configuration instance.
521      *
522      * @return The current setting of {@code minEvictableIdleTime} for this configuration instance
523      * @see GenericObjectPool#getMinEvictableIdleDuration()
524      * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
525      * @deprecated Use {@link #getMinEvictableIdleTime()}.
526      */
527     @Deprecated
528     public long getMinEvictableIdleTimeMillis() {
529         return minEvictableIdleDuration.toMillis();
530     }
531 
532     /**
533      * Gets the value for the {@code numTestsPerEvictionRun} configuration attribute for pools created with this configuration instance.
534      *
535      * @return The current setting of {@code numTestsPerEvictionRun} for this configuration instance
536      * @see GenericObjectPool#getNumTestsPerEvictionRun()
537      * @see GenericKeyedObjectPool#getNumTestsPerEvictionRun()
538      */
539     public int getNumTestsPerEvictionRun() {
540         return numTestsPerEvictionRun;
541     }
542 
543     /**
544      * Gets the value for the {@code softMinEvictableIdleTime} configuration attribute for pools created with this configuration instance.
545      *
546      * @return The current setting of {@code softMinEvictableIdleTime} for this configuration instance
547      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
548      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
549      * @since 2.11.0
550      */
551     public Duration getSoftMinEvictableIdleDuration() {
552         return softMinEvictableIdleDuration;
553     }
554 
555     /**
556      * Gets the value for the {@code softMinEvictableIdleTime} configuration attribute for pools created with this configuration instance.
557      *
558      * @return The current setting of {@code softMinEvictableIdleTime} for this configuration instance
559      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
560      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
561      * @since 2.10.0
562      * @deprecated Use {@link #getSoftMinEvictableIdleDuration()}.
563      */
564     @Deprecated
565     public Duration getSoftMinEvictableIdleTime() {
566         return softMinEvictableIdleDuration;
567     }
568 
569     /**
570      * Gets the value for the {@code softMinEvictableIdleTime} configuration attribute for pools created with this configuration instance.
571      *
572      * @return The current setting of {@code softMinEvictableIdleTime} for this configuration instance
573      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
574      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
575      * @deprecated Use {@link #getSoftMinEvictableIdleDuration()}.
576      */
577     @Deprecated
578     public long getSoftMinEvictableIdleTimeMillis() {
579         return softMinEvictableIdleDuration.toMillis();
580     }
581 
582     /**
583      * Gets the value for the {@code testOnBorrow} configuration attribute for pools created with this configuration instance.
584      *
585      * @return The current setting of {@code testOnBorrow} for this configuration instance
586      * @see GenericObjectPool#getTestOnBorrow()
587      * @see GenericKeyedObjectPool#getTestOnBorrow()
588      */
589     public boolean getTestOnBorrow() {
590         return testOnBorrow;
591     }
592 
593     /**
594      * Gets the value for the {@code testOnCreate} configuration attribute for pools created with this configuration instance.
595      *
596      * @return The current setting of {@code testOnCreate} for this configuration instance
597      * @see GenericObjectPool#getTestOnCreate()
598      * @see GenericKeyedObjectPool#getTestOnCreate()
599      * @since 2.2
600      */
601     public boolean getTestOnCreate() {
602         return testOnCreate;
603     }
604 
605     /**
606      * Gets the value for the {@code testOnReturn} configuration attribute for pools created with this configuration instance.
607      *
608      * @return The current setting of {@code testOnReturn} for this configuration instance
609      * @see GenericObjectPool#getTestOnReturn()
610      * @see GenericKeyedObjectPool#getTestOnReturn()
611      */
612     public boolean getTestOnReturn() {
613         return testOnReturn;
614     }
615 
616     /**
617      * Gets the value for the {@code testWhileIdle} configuration attribute for pools created with this configuration instance.
618      *
619      * @return The current setting of {@code testWhileIdle} for this configuration instance
620      * @see GenericObjectPool#getTestWhileIdle()
621      * @see GenericKeyedObjectPool#getTestWhileIdle()
622      */
623     public boolean getTestWhileIdle() {
624         return testWhileIdle;
625     }
626 
627     /**
628      * Gets the value for the {@code timeBetweenEvictionRuns} configuration attribute for pools created with this configuration instance.
629      *
630      * @return The current setting of {@code timeBetweenEvictionRuns} for this configuration instance
631      * @see GenericObjectPool#getDurationBetweenEvictionRuns()
632      * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
633      * @since 2.10.0
634      * @deprecated Use {@link #getDurationBetweenEvictionRuns()}.
635      */
636     @Deprecated
637     public Duration getTimeBetweenEvictionRuns() {
638         return durationBetweenEvictionRuns;
639     }
640 
641     /**
642      * Gets the value for the {@code timeBetweenEvictionRuns} configuration attribute for pools created with this configuration instance.
643      *
644      * @return The current setting of {@code timeBetweenEvictionRuns} for this configuration instance
645      * @see GenericObjectPool#getDurationBetweenEvictionRuns()
646      * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
647      * @deprecated Use {@link #getDurationBetweenEvictionRuns()}.
648      */
649     @Deprecated
650     public long getTimeBetweenEvictionRunsMillis() {
651         return durationBetweenEvictionRuns.toMillis();
652     }
653 
654     /**
655      * Sets the value for the {@code blockWhenExhausted} configuration attribute for pools created with this configuration instance.
656      *
657      * @param blockWhenExhausted The new setting of {@code blockWhenExhausted} for this configuration instance
658      * @see GenericObjectPool#getBlockWhenExhausted()
659      * @see GenericKeyedObjectPool#getBlockWhenExhausted()
660      */
661     public void setBlockWhenExhausted(final boolean blockWhenExhausted) {
662         this.blockWhenExhausted = blockWhenExhausted;
663     }
664 
665     /**
666      * Sets the value for the {@code collectDetailedStatistics} configuration attribute
667      * for pools created with this configuration instance. When {@code false}, the pool
668      * will not collect detailed timing statistics, improving performance under high load
669      * at the cost of reduced monitoring capabilities.
670      * <p>
671      * This setting affects data collection for mean active time, mean idle time, and mean borrow wait time.
672      * </p>
673      *
674      * @param collectDetailedStatistics The new setting of {@code collectDetailedStatistics}
675      *        for this configuration instance.
676      * @see GenericObjectPool#getCollectDetailedStatistics()
677      * @see GenericKeyedObjectPool#getCollectDetailedStatistics()
678      * @since 2.13.0
679      */
680     public void setCollectDetailedStatistics(final boolean collectDetailedStatistics) {
681         this.collectDetailedStatistics = collectDetailedStatistics;
682     }
683 
684     /**
685      * Sets the value for the {@code evictionPolicyClass} configuration attribute for pools created with this configuration instance.
686      *
687      * @param evictionPolicy The new setting of {@code evictionPolicyClass} for this configuration instance
688      * @see GenericObjectPool#getEvictionPolicy()
689      * @see GenericKeyedObjectPool#getEvictionPolicy()
690      * @since 2.6.0
691      */
692     public void setEvictionPolicy(final EvictionPolicy<T> evictionPolicy) {
693         this.evictionPolicy = evictionPolicy;
694     }
695 
696     /**
697      * Sets the value for the {@code evictionPolicyClassName} configuration attribute for pools created with this configuration instance.
698      *
699      * @param evictionPolicyClassName The new setting of {@code evictionPolicyClassName} for this configuration instance
700      * @see GenericObjectPool#getEvictionPolicyClassName()
701      * @see GenericKeyedObjectPool#getEvictionPolicyClassName()
702      */
703     public void setEvictionPolicyClassName(final String evictionPolicyClassName) {
704         this.evictionPolicyClassName = evictionPolicyClassName;
705     }
706 
707     /**
708      * Sets the value for the {@code evictorShutdownTimeout} configuration attribute for pools created with this configuration instance.
709      *
710      * @param evictorShutdownTimeoutDuration The new setting of {@code evictorShutdownTimeout} for this configuration instance
711      * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
712      * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
713      * @since 2.11.0
714      */
715     public void setEvictorShutdownTimeout(final Duration evictorShutdownTimeoutDuration) {
716         this.evictorShutdownTimeoutDuration = PoolImplUtils.nonNull(evictorShutdownTimeoutDuration, DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT);
717     }
718 
719     /**
720      * Sets the value for the {@code evictorShutdownTimeout} configuration attribute for pools created with this configuration instance.
721      *
722      * @param evictorShutdownTimeout The new setting of {@code evictorShutdownTimeout} for this configuration instance
723      * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
724      * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
725      * @since 2.10.0
726      * @deprecated Use {@link #setEvictorShutdownTimeout(Duration)}.
727      */
728     @Deprecated
729     public void setEvictorShutdownTimeoutMillis(final Duration evictorShutdownTimeout) {
730         setEvictorShutdownTimeout(evictorShutdownTimeout);
731     }
732 
733     /**
734      * Sets the value for the {@code evictorShutdownTimeout} configuration attribute for pools created with this configuration instance.
735      *
736      * @param evictorShutdownTimeoutMillis The new setting of {@code evictorShutdownTimeout} for this configuration instance
737      * @see GenericObjectPool#getEvictorShutdownTimeoutDuration()
738      * @see GenericKeyedObjectPool#getEvictorShutdownTimeoutDuration()
739      * @deprecated Use {@link #setEvictorShutdownTimeout(Duration)}.
740      */
741     @Deprecated
742     public void setEvictorShutdownTimeoutMillis(final long evictorShutdownTimeoutMillis) {
743         setEvictorShutdownTimeout(Duration.ofMillis(evictorShutdownTimeoutMillis));
744     }
745 
746     /**
747      * Sets the value for the {@code fairness} configuration attribute for pools created with this configuration instance.
748      *
749      * @param fairness The new setting of {@code fairness} for this configuration instance
750      * @see GenericObjectPool#getFairness()
751      * @see GenericKeyedObjectPool#getFairness()
752      */
753     public void setFairness(final boolean fairness) {
754         this.fairness = fairness;
755     }
756 
757     /**
758      * Sets the value of the flag that determines if JMX will be enabled for pools created with this configuration instance.
759      *
760      * @param jmxEnabled The new setting of {@code jmxEnabled} for this configuration instance
761      */
762     public void setJmxEnabled(final boolean jmxEnabled) {
763         this.jmxEnabled = jmxEnabled;
764     }
765 
766     /**
767      * Sets the value of the JMX name base that will be used as part of the name assigned to JMX enabled pools created with this configuration instance. A value
768      * of {@code null} means that the pool will define the JMX name base.
769      *
770      * @param jmxNameBase The new setting of {@code jmxNameBase} for this configuration instance
771      */
772     public void setJmxNameBase(final String jmxNameBase) {
773         this.jmxNameBase = jmxNameBase;
774     }
775 
776     /**
777      * Sets the value of the JMX name prefix that will be used as part of the name assigned to JMX enabled pools created with this configuration instance.
778      *
779      * @param jmxNamePrefix The new setting of {@code jmxNamePrefix} for this configuration instance
780      */
781     public void setJmxNamePrefix(final String jmxNamePrefix) {
782         this.jmxNamePrefix = jmxNamePrefix;
783     }
784 
785     /**
786      * Sets the value for the {@code lifo} configuration attribute for pools created with this configuration instance.
787      *
788      * @param lifo The new setting of {@code lifo} for this configuration instance
789      * @see GenericObjectPool#getLifo()
790      * @see GenericKeyedObjectPool#getLifo()
791      */
792     public void setLifo(final boolean lifo) {
793         this.lifo = lifo;
794     }
795 
796     /**
797      * Sets the value for the {@code maxWait} configuration attribute for pools created with this configuration instance.
798      *
799      * @param maxWaitDuration The new setting of {@code maxWaitDuration} for this configuration instance
800      * @see GenericObjectPool#getMaxWaitDuration()
801      * @see GenericKeyedObjectPool#getMaxWaitDuration()
802      * @since 2.11.0
803      */
804     public void setMaxWait(final Duration maxWaitDuration) {
805         this.maxWaitDuration = PoolImplUtils.nonNull(maxWaitDuration, DEFAULT_MAX_WAIT);
806     }
807 
808     /**
809      * Sets the value for the {@code maxWait} configuration attribute for pools created with this configuration instance.
810      *
811      * @param maxWaitMillis The new setting of {@code maxWaitMillis} for this configuration instance
812      * @see GenericObjectPool#getMaxWaitDuration()
813      * @see GenericKeyedObjectPool#getMaxWaitDuration()
814      * @deprecated Use {@link #setMaxWait(Duration)}.
815      */
816     @Deprecated
817     public void setMaxWaitMillis(final long maxWaitMillis) {
818         setMaxWait(Duration.ofMillis(maxWaitMillis));
819     }
820 
821     /**
822      * Sets the value for the {@code minEvictableIdleTime} configuration attribute for pools created with this configuration instance.
823      *
824      * @param minEvictableIdleTime The new setting of {@code minEvictableIdleTime} for this configuration instance
825      * @see GenericObjectPool#getMinEvictableIdleDuration()
826      * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
827      * @since 2.12.0
828      */
829     public void setMinEvictableIdleDuration(final Duration minEvictableIdleTime) {
830         this.minEvictableIdleDuration = PoolImplUtils.nonNull(minEvictableIdleTime, DEFAULT_MIN_EVICTABLE_IDLE_TIME);
831     }
832 
833     /**
834      * Sets the value for the {@code minEvictableIdleTime} configuration attribute for pools created with this configuration instance.
835      *
836      * @param minEvictableIdleTime The new setting of {@code minEvictableIdleTime} for this configuration instance
837      * @see GenericObjectPool#getMinEvictableIdleDuration()
838      * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
839      * @since 2.10.0
840      * @deprecated Use {@link #setMinEvictableIdleDuration(Duration)}.
841      */
842     @Deprecated
843     public void setMinEvictableIdleTime(final Duration minEvictableIdleTime) {
844         this.minEvictableIdleDuration = PoolImplUtils.nonNull(minEvictableIdleTime, DEFAULT_MIN_EVICTABLE_IDLE_TIME);
845     }
846 
847     /**
848      * Sets the value for the {@code minEvictableIdleTime} configuration attribute for pools created with this configuration instance.
849      *
850      * @param minEvictableIdleTimeMillis The new setting of {@code minEvictableIdleTime} for this configuration instance
851      * @see GenericObjectPool#getMinEvictableIdleDuration()
852      * @see GenericKeyedObjectPool#getMinEvictableIdleDuration()
853      * @deprecated Use {@link #setMinEvictableIdleDuration(Duration)}.
854      */
855     @Deprecated
856     public void setMinEvictableIdleTimeMillis(final long minEvictableIdleTimeMillis) {
857         this.minEvictableIdleDuration = Duration.ofMillis(minEvictableIdleTimeMillis);
858     }
859 
860     /**
861      * Sets the value for the {@code numTestsPerEvictionRun} configuration attribute for pools created with this configuration instance.
862      *
863      * @param numTestsPerEvictionRun The new setting of {@code numTestsPerEvictionRun} for this configuration instance
864      * @see GenericObjectPool#getNumTestsPerEvictionRun()
865      * @see GenericKeyedObjectPool#getNumTestsPerEvictionRun()
866      */
867     public void setNumTestsPerEvictionRun(final int numTestsPerEvictionRun) {
868         this.numTestsPerEvictionRun = numTestsPerEvictionRun;
869     }
870 
871     /**
872      * Sets the value for the {@code softMinEvictableIdleTime} configuration attribute for pools created with this configuration instance.
873      *
874      * @param softMinEvictableIdleTime The new setting of {@code softMinEvictableIdleTime} for this configuration instance
875      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
876      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
877      * @since 2.12.0
878      */
879     public void setSoftMinEvictableIdleDuration(final Duration softMinEvictableIdleTime) {
880         this.softMinEvictableIdleDuration = PoolImplUtils.nonNull(softMinEvictableIdleTime, DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME);
881     }
882 
883     /**
884      * Sets the value for the {@code softMinEvictableIdleTime} configuration attribute for pools created with this configuration instance.
885      *
886      * @param softMinEvictableIdleTime The new setting of {@code softMinEvictableIdleTime} for this configuration instance
887      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
888      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
889      * @since 2.10.0
890      * @deprecated Use {@link #setSoftMinEvictableIdleDuration(Duration)}.
891      */
892     @Deprecated
893     public void setSoftMinEvictableIdleTime(final Duration softMinEvictableIdleTime) {
894         this.softMinEvictableIdleDuration = PoolImplUtils.nonNull(softMinEvictableIdleTime, DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME);
895     }
896 
897     /**
898      * Sets the value for the {@code softMinEvictableIdleTime} configuration attribute for pools created with this configuration instance.
899      *
900      * @param softMinEvictableIdleTimeMillis The new setting of {@code softMinEvictableIdleTime} for this configuration instance
901      * @see GenericObjectPool#getSoftMinEvictableIdleDuration()
902      * @see GenericKeyedObjectPool#getSoftMinEvictableIdleDuration()
903      * @deprecated Use {@link #setSoftMinEvictableIdleDuration(Duration)}.
904      */
905     @Deprecated
906     public void setSoftMinEvictableIdleTimeMillis(final long softMinEvictableIdleTimeMillis) {
907         setSoftMinEvictableIdleTime(Duration.ofMillis(softMinEvictableIdleTimeMillis));
908     }
909 
910     /**
911      * Sets the value for the {@code testOnBorrow} configuration attribute for pools created with this configuration instance.
912      *
913      * @param testOnBorrow The new setting of {@code testOnBorrow} for this configuration instance
914      * @see GenericObjectPool#getTestOnBorrow()
915      * @see GenericKeyedObjectPool#getTestOnBorrow()
916      */
917     public void setTestOnBorrow(final boolean testOnBorrow) {
918         this.testOnBorrow = testOnBorrow;
919     }
920 
921     /**
922      * Sets the value for the {@code testOnCreate} configuration attribute for pools created with this configuration instance.
923      *
924      * @param testOnCreate The new setting of {@code testOnCreate} for this configuration instance
925      * @see GenericObjectPool#getTestOnCreate()
926      * @see GenericKeyedObjectPool#getTestOnCreate()
927      * @since 2.2
928      */
929     public void setTestOnCreate(final boolean testOnCreate) {
930         this.testOnCreate = testOnCreate;
931     }
932 
933     /**
934      * Sets the value for the {@code testOnReturn} configuration attribute for pools created with this configuration instance.
935      *
936      * @param testOnReturn The new setting of {@code testOnReturn} for this configuration instance
937      * @see GenericObjectPool#getTestOnReturn()
938      * @see GenericKeyedObjectPool#getTestOnReturn()
939      */
940     public void setTestOnReturn(final boolean testOnReturn) {
941         this.testOnReturn = testOnReturn;
942     }
943 
944     /**
945      * Sets the value for the {@code testWhileIdle} configuration attribute for pools created with this configuration instance.
946      *
947      * @param testWhileIdle The new setting of {@code testWhileIdle} for this configuration instance
948      * @see GenericObjectPool#getTestWhileIdle()
949      * @see GenericKeyedObjectPool#getTestWhileIdle()
950      */
951     public void setTestWhileIdle(final boolean testWhileIdle) {
952         this.testWhileIdle = testWhileIdle;
953     }
954 
955     /**
956      * Sets the value for the {@code timeBetweenEvictionRuns} configuration attribute for pools created with this configuration instance.
957      *
958      * @param timeBetweenEvictionRuns The new setting of {@code timeBetweenEvictionRuns} for this configuration instance
959      * @see GenericObjectPool#getDurationBetweenEvictionRuns()
960      * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
961      * @since 2.10.0
962      */
963     public void setTimeBetweenEvictionRuns(final Duration timeBetweenEvictionRuns) {
964         this.durationBetweenEvictionRuns = PoolImplUtils.nonNull(timeBetweenEvictionRuns, DEFAULT_DURATION_BETWEEN_EVICTION_RUNS);
965     }
966 
967     /**
968      * Sets the value for the {@code timeBetweenEvictionRuns} configuration attribute for pools created with this configuration instance.
969      *
970      * @param timeBetweenEvictionRunsMillis The new setting of {@code timeBetweenEvictionRuns} for this configuration instance
971      * @see GenericObjectPool#getDurationBetweenEvictionRuns()
972      * @see GenericKeyedObjectPool#getDurationBetweenEvictionRuns()
973      * @deprecated Use {@link #setTimeBetweenEvictionRuns(Duration)}.
974      */
975     @Deprecated
976     public void setTimeBetweenEvictionRunsMillis(final long timeBetweenEvictionRunsMillis) {
977         setTimeBetweenEvictionRuns(Duration.ofMillis(timeBetweenEvictionRunsMillis));
978     }
979 
980     @Override
981     protected void toStringAppendFields(final StringBuilder builder) {
982         builder.append("lifo=");
983         builder.append(lifo);
984         builder.append(", fairness=");
985         builder.append(fairness);
986         builder.append(", maxWaitDuration=");
987         builder.append(maxWaitDuration);
988         builder.append(", minEvictableIdleTime=");
989         builder.append(minEvictableIdleDuration);
990         builder.append(", softMinEvictableIdleTime=");
991         builder.append(softMinEvictableIdleDuration);
992         builder.append(", numTestsPerEvictionRun=");
993         builder.append(numTestsPerEvictionRun);
994         builder.append(", evictionPolicyClassName=");
995         builder.append(evictionPolicyClassName);
996         builder.append(", testOnCreate=");
997         builder.append(testOnCreate);
998         builder.append(", testOnBorrow=");
999         builder.append(testOnBorrow);
1000         builder.append(", testOnReturn=");
1001         builder.append(testOnReturn);
1002         builder.append(", testWhileIdle=");
1003         builder.append(testWhileIdle);
1004         builder.append(", timeBetweenEvictionRuns=");
1005         builder.append(durationBetweenEvictionRuns);
1006         builder.append(", blockWhenExhausted=");
1007         builder.append(blockWhenExhausted);
1008         builder.append(", jmxEnabled=");
1009         builder.append(jmxEnabled);
1010         builder.append(", jmxNamePrefix=");
1011         builder.append(jmxNamePrefix);
1012         builder.append(", jmxNameBase=");
1013         builder.append(jmxNameBase);
1014         builder.append(", collectDetailedStatistics=");
1015         builder.append(collectDetailedStatistics);
1016     }
1017 }