@@ -60,6 +60,8 @@ public static final class Builder {
60
60
61
61
private String pollThreadNamePrefix ;
62
62
63
+ private Boolean pollOnlyIfExecutorHasCapacity = Boolean .FALSE ;
64
+
63
65
private Thread .UncaughtExceptionHandler uncaughtExceptionHandler ;
64
66
65
67
private Builder () {}
@@ -75,6 +77,7 @@ private Builder(PollerOptions o) {
75
77
this .pollBackoffMaximumInterval = o .getPollBackoffMaximumInterval ();
76
78
this .pollThreadCount = o .getPollThreadCount ();
77
79
this .pollThreadNamePrefix = o .getPollThreadNamePrefix ();
80
+ this .pollOnlyIfExecutorHasCapacity = o .getPollOnlyIfExecutorHasCapacity ();
78
81
this .uncaughtExceptionHandler = o .getUncaughtExceptionHandler ();
79
82
}
80
83
@@ -133,6 +136,15 @@ public Builder setPollThreadNamePrefix(String pollThreadNamePrefix) {
133
136
return this ;
134
137
}
135
138
139
+ /**
140
+ * The poller will check task executor's remaining capacity before polling tasks.
141
+ * This is to prevent task to get started but not being able to execute in time.
142
+ */
143
+ public Builder setPollOnlyIfExecutorHasCapacity (boolean pollOnlyIfExecutorHasCapacity ) {
144
+ this .pollOnlyIfExecutorHasCapacity = pollOnlyIfExecutorHasCapacity ;
145
+ return this ;
146
+ }
147
+
136
148
public PollerOptions build () {
137
149
if (uncaughtExceptionHandler == null ) {
138
150
uncaughtExceptionHandler = (t , e ) -> log .error ("uncaught exception" , e );
@@ -145,7 +157,8 @@ public PollerOptions build() {
145
157
pollBackoffMaximumInterval ,
146
158
pollThreadCount ,
147
159
uncaughtExceptionHandler ,
148
- pollThreadNamePrefix );
160
+ pollThreadNamePrefix ,
161
+ pollOnlyIfExecutorHasCapacity );
149
162
}
150
163
}
151
164
@@ -165,6 +178,8 @@ public PollerOptions build() {
165
178
166
179
private final String pollThreadNamePrefix ;
167
180
181
+ private final Boolean pollOnlyIfExecutorHasCapacity ;
182
+
168
183
private PollerOptions (
169
184
int maximumPollRateIntervalMilliseconds ,
170
185
double maximumPollRatePerSecond ,
@@ -173,7 +188,8 @@ private PollerOptions(
173
188
Duration pollBackoffMaximumInterval ,
174
189
int pollThreadCount ,
175
190
Thread .UncaughtExceptionHandler uncaughtExceptionHandler ,
176
- String pollThreadNamePrefix ) {
191
+ String pollThreadNamePrefix ,
192
+ boolean pollOnlyIfExecutorHasCapacity ) {
177
193
this .maximumPollRateIntervalMilliseconds = maximumPollRateIntervalMilliseconds ;
178
194
this .maximumPollRatePerSecond = maximumPollRatePerSecond ;
179
195
this .pollBackoffCoefficient = pollBackoffCoefficient ;
@@ -182,6 +198,7 @@ private PollerOptions(
182
198
this .pollThreadCount = pollThreadCount ;
183
199
this .uncaughtExceptionHandler = uncaughtExceptionHandler ;
184
200
this .pollThreadNamePrefix = pollThreadNamePrefix ;
201
+ this .pollOnlyIfExecutorHasCapacity = pollOnlyIfExecutorHasCapacity ;
185
202
}
186
203
187
204
public int getMaximumPollRateIntervalMilliseconds () {
@@ -216,6 +233,10 @@ public String getPollThreadNamePrefix() {
216
233
return pollThreadNamePrefix ;
217
234
}
218
235
236
+ public Boolean getPollOnlyIfExecutorHasCapacity () {
237
+ return pollOnlyIfExecutorHasCapacity ;
238
+ }
239
+
219
240
@ Override
220
241
public String toString () {
221
242
return "PollerOptions{"
@@ -233,6 +254,8 @@ public String toString() {
233
254
+ pollThreadCount
234
255
+ ", pollThreadNamePrefix='"
235
256
+ pollThreadNamePrefix
257
+ + ", pollOnlyIfExecutorHasCapacity='"
258
+ + pollOnlyIfExecutorHasCapacity
236
259
+ '\''
237
260
+ '}' ;
238
261
}
0 commit comments