@@ -133,7 +133,7 @@ public class SimpleObjectPoolConfig {
133
133
*/
134
134
private final long waitingForObjectTimeout ;
135
135
136
- private SimpleObjectPoolConfig (Builder builder ) {
136
+ protected SimpleObjectPoolConfig (Builder builder ) {
137
137
this .maxPoolSize = builder .maxPoolSize ;
138
138
this .minPoolSize = builder .minPoolSize ;
139
139
this .fairness = builder .fairness ;
@@ -195,7 +195,7 @@ public enum EvictionPolicy {
195
195
public static class Builder {
196
196
private int maxPoolSize = 8 ;
197
197
private int minPoolSize = 0 ;
198
- private boolean fairness = true ;
198
+ private boolean fairness = false ;
199
199
private boolean testOnCreate = false ;
200
200
private boolean testOnBorrow = true ;
201
201
private boolean testOnReturn = false ;
@@ -223,6 +223,9 @@ public Builder maxPoolSize(int maxPoolSize) {
223
223
224
224
/**
225
225
* Sets the minimum number of objects that the pool should maintain.
226
+ * Note setting a positive value does not guarantee that the pool will have at least the specified number
227
+ * of objects rather it suggests that the pool should attempt to maintain the specified number of objects.
228
+ * Especially in case of evictionsruns the pool may not be able to maintain the specified number of objects.
226
229
*
227
230
* @param minPoolSize The minimum pool size.
228
231
* @return This {@code Builder} instance.
@@ -323,6 +326,12 @@ public Builder durationBetweenEvictionsRuns(Duration durationBetweenEvictionsRun
323
326
/**
324
327
* Sets the timeout duration for an object from its creation time to be considered for
325
328
* eviction.
329
+ * <br>
330
+ * If set to 0 then eviction will be immediate.
331
+ * <p>
332
+ * Note: if you want eviction only based on object validation then set
333
+ * this to a very high value in the range of hours or days.
334
+ * </p>
326
335
*
327
336
* @param objEvictionTimeout The object idle timeout duration.
328
337
* @return This {@code Builder} instance.
@@ -389,6 +398,13 @@ public Builder retryCreationDelay(Duration retryCreationDelay) {
389
398
390
399
/**
391
400
* Sets the timeout duration for waiting for an object to become available in the pool.
401
+ * The default value is 10 seconds if not set.
402
+ * <p>
403
+ * If the timeout is set to 0 or negative values then the pool will not wait for an object to become available if the pool is empty
404
+ * but will throw an exception instead.
405
+ * <p>
406
+ * if you want to wait indefinitely then use a very large value in the range of hours or days.
407
+ * Setting a very high value is not recommended, rather handle the cases with much shorter timeouts.
392
408
*
393
409
* @param waitingForObjectTimeout The waiting for object timeout duration.
394
410
* @return This {@code Builder} instance.
@@ -404,7 +420,7 @@ public Builder waitingForObjectTimeout(Duration waitingForObjectTimeout) {
404
420
* This method will throw an exception if any of the configuration settings are invalid.
405
421
* It will also log warnings if any of the settings may result in unexpected behavior.
406
422
*/
407
- public void validate () {
423
+ protected void validate () {
408
424
if (maxPoolSize < 1 ) {
409
425
throw new IllegalArgumentException ("maxPoolSize must be greater than 0" );
410
426
}
@@ -466,7 +482,7 @@ public void validate() {
466
482
467
483
}
468
484
469
- public SimpleObjectPoolConfig build () {
485
+ protected Builder prepareAndCheck () {
470
486
if (numValidationsPerEvictionRun == null ) {
471
487
numValidationsPerEvictionRun = maxPoolSize ;
472
488
}
@@ -476,9 +492,13 @@ public SimpleObjectPoolConfig build() {
476
492
maxRetries = 1 ;
477
493
}
478
494
}
479
- SimpleObjectPoolConfig config = new SimpleObjectPoolConfig (this );
480
495
validate ();
481
- return config ;
496
+ return this ;
497
+ }
498
+
499
+ public SimpleObjectPoolConfig build () {
500
+ prepareAndCheck ();
501
+ return new SimpleObjectPoolConfig (this );
482
502
}
483
503
}
484
504
}
0 commit comments