@@ -52,6 +52,11 @@ public final class ConnectionPoolConfiguration {
5252 */
5353 public static final Duration NO_TIMEOUT = Duration .ofMillis (-1 );
5454
55+ /**
56+ * Constant indicating the default parallelism used during connection pool warmup.
57+ */
58+ public static final int DEFAULT_WARMUP_PARALLELISM = 1 ;
59+
5560 @ Nullable
5661 private final Scheduler allocatorSubscribeOn ;
5762
@@ -99,12 +104,14 @@ public final class ConnectionPoolConfiguration {
99104 @ Nullable
100105 private final String validationQuery ;
101106
107+ private final int warmupParallelism ;
108+
102109 private ConnectionPoolConfiguration (@ Nullable Scheduler allocatorSubscribeOn , int acquireRetry , @ Nullable Duration backgroundEvictionInterval , ConnectionFactory connectionFactory , Clock clock , Consumer <PoolBuilder <Connection , ?
103110 extends PoolConfig <? extends Connection >>> customizer , int initialSize , int maxSize , int minIdle , Duration maxAcquireTime , Duration maxCreateConnectionTime , Duration maxIdleTime ,
104111 Duration maxLifeTime , Duration maxValidationTime , PoolMetricsRecorder metricsRecorder , @ Nullable String name ,
105112 @ Nullable Function <? super Connection , ? extends Publisher <Void >> postAllocate ,
106113 @ Nullable Function <? super Connection , ? extends Publisher <Void >> preRelease , boolean registerJmx , ValidationDepth validationDepth ,
107- @ Nullable String validationQuery ) {
114+ @ Nullable String validationQuery , int warmupParallelism ) {
108115 this .allocatorSubscribeOn = allocatorSubscribeOn ;
109116 this .acquireRetry = acquireRetry ;
110117 this .connectionFactory = Assert .requireNonNull (connectionFactory , "ConnectionFactory must not be null" );
@@ -126,6 +133,7 @@ private ConnectionPoolConfiguration(@Nullable Scheduler allocatorSubscribeOn, in
126133 this .validationDepth = validationDepth ;
127134 this .validationQuery = validationQuery ;
128135 this .backgroundEvictionInterval = backgroundEvictionInterval ;
136+ this .warmupParallelism = warmupParallelism ;
129137 }
130138
131139 /**
@@ -237,6 +245,10 @@ String getValidationQuery() {
237245 return this .validationQuery ;
238246 }
239247
248+ int getWarmupParallelism () {
249+ return this .warmupParallelism ;
250+ }
251+
240252 /**
241253 * A builder for {@link ConnectionPoolConfiguration} instances.
242254 * <p>
@@ -293,6 +305,8 @@ public static final class Builder {
293305
294306 private ValidationDepth validationDepth = ValidationDepth .LOCAL ;
295307
308+ private Integer warmupParallelism = DEFAULT_WARMUP_PARALLELISM ;
309+
296310 private Builder () {
297311 }
298312
@@ -583,6 +597,23 @@ public Builder validationQuery(String validationQuery) {
583597 return this ;
584598 }
585599
600+ /**
601+ * Configure the concurrency level used when the allocator is subscribed to during the warmup phase.
602+ *
603+ * @param warmupParallelism Specifies the concurrency level used when the allocator is subscribed to during the warmup phase, if any.
604+ * During warmup, resources that can be pre-allocated will be created eagerly, but at most {@code warmupParallelism} resources are
605+ * subscribed to at the same time.
606+ * @return this {@link Builder}
607+ * @throws IllegalArgumentException if {@code warmupParallelism} is negative
608+ */
609+ public Builder warmupParallelism (int warmupParallelism ) {
610+ if (warmupParallelism < 0 ) {
611+ throw new IllegalArgumentException ("warmupParallelism must not be negative" );
612+ }
613+ this .warmupParallelism = warmupParallelism ;
614+ return this ;
615+ }
616+
586617 /**
587618 * Returns a configured {@link ConnectionPoolConfiguration}.
588619 *
@@ -596,7 +627,7 @@ public ConnectionPoolConfiguration build() {
596627 this .clock , this .customizer , this .initialSize , this .maxSize , this .minIdle ,
597628 this .maxAcquireTime , this .maxCreateConnectionTime , this .maxIdleTime , this .maxLifeTime , this .maxValidationTime ,
598629 this .metricsRecorder , this .name , this .postAllocate , this .preRelease , this .registerJmx ,
599- this .validationDepth , this .validationQuery
630+ this .validationDepth , this .validationQuery , this . warmupParallelism
600631 );
601632 }
602633
0 commit comments