diff --git a/transactionoutbox-core/src/main/java/com/gruelbox/transactionoutbox/TransactionOutbox.java b/transactionoutbox-core/src/main/java/com/gruelbox/transactionoutbox/TransactionOutbox.java index 51e0ab59..76b79b5b 100644 --- a/transactionoutbox-core/src/main/java/com/gruelbox/transactionoutbox/TransactionOutbox.java +++ b/transactionoutbox-core/src/main/java/com/gruelbox/transactionoutbox/TransactionOutbox.java @@ -3,6 +3,7 @@ import java.time.Clock; import java.time.Duration; import java.util.concurrent.Executor; +import java.util.concurrent.ThreadFactory; import java.util.function.Supplier; import lombok.ToString; import org.slf4j.MDC; @@ -152,6 +153,7 @@ abstract class TransactionOutboxBuilder { protected Boolean serializeMdc; protected Duration retentionThreshold; protected Boolean initializeImmediately; + protected ThreadFactory schedulerThreadFactory; protected TransactionOutboxBuilder() {} @@ -298,6 +300,15 @@ public TransactionOutboxBuilder initializeImmediately(boolean initializeImmediat return this; } + /** + * @param schedulerThreadFactory The {@link ThreadFactory} that will be used to build the scheduler executor. + * @return Builder. + */ + public TransactionOutboxBuilder schedulerThreadFactory(ThreadFactory schedulerThreadFactory) { + this.schedulerThreadFactory = schedulerThreadFactory; + return this; + } + /** * Creates and initialises the {@link TransactionOutbox}. * diff --git a/transactionoutbox-core/src/main/java/com/gruelbox/transactionoutbox/TransactionOutboxImpl.java b/transactionoutbox-core/src/main/java/com/gruelbox/transactionoutbox/TransactionOutboxImpl.java index feb5b1bd..1b7fd2e8 100644 --- a/transactionoutbox-core/src/main/java/com/gruelbox/transactionoutbox/TransactionOutboxImpl.java +++ b/transactionoutbox-core/src/main/java/com/gruelbox/transactionoutbox/TransactionOutboxImpl.java @@ -51,7 +51,7 @@ final class TransactionOutboxImpl implements TransactionOutbox, Validatable { private final Duration retentionThreshold; private final AtomicBoolean initialized = new AtomicBoolean(); private final ProxyFactory proxyFactory = new ProxyFactory(); - private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); + private final ScheduledExecutorService scheduler; @Override public void validate(Validator validator) { @@ -435,7 +435,8 @@ public TransactionOutboxImpl build() { Utils.firstNonNull(listener, () -> TransactionOutboxListener.EMPTY), serializeMdc == null || serializeMdc, validator, - retentionThreshold == null ? Duration.ofDays(7) : retentionThreshold); + retentionThreshold == null ? Duration.ofDays(7) : retentionThreshold, + schedulerThreadFactory == null? Executors.newSingleThreadScheduledExecutor() : Executors.newSingleThreadScheduledExecutor(schedulerThreadFactory)); validator.validate(impl); if (initializeImmediately == null || initializeImmediately) { impl.initialize();