Skip to content

Commit

Permalink
Merge pull request #135 from kilink/lazy-init-executor
Browse files Browse the repository at this point in the history
Lazily initialize Executor in ScheduledDataLoaderRegistry builder
  • Loading branch information
bbakerman authored Nov 12, 2023
2 parents 5f8ec4a + 789b8ca commit b4d67cc
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public static class Builder {
private final Map<String, DataLoader<?, ?>> dataLoaders = new LinkedHashMap<>();
private final Map<DataLoader<?, ?>, DispatchPredicate> dataLoaderPredicates = new LinkedHashMap<>();
private DispatchPredicate dispatchPredicate = DispatchPredicate.DISPATCH_ALWAYS;
private ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
private ScheduledExecutorService scheduledExecutorService;
private Duration schedule = Duration.ofMillis(10);
private boolean tickerMode = false;

Expand Down Expand Up @@ -348,6 +348,9 @@ public Builder tickerMode(boolean tickerMode) {
* @return the newly built {@link ScheduledDataLoaderRegistry}
*/
public ScheduledDataLoaderRegistry build() {
if (scheduledExecutorService == null) {
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
}
return new ScheduledDataLoaderRegistry(this);
}
}
Expand Down

0 comments on commit b4d67cc

Please sign in to comment.