Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -152,6 +153,7 @@ abstract class TransactionOutboxBuilder {
protected Boolean serializeMdc;
protected Duration retentionThreshold;
protected Boolean initializeImmediately;
protected ThreadFactory schedulerThreadFactory;

protected TransactionOutboxBuilder() {}

Expand Down Expand Up @@ -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}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down