Skip to content

Commit ae62d1a

Browse files
committed
fix: Create a dedicated thread for start
1 parent 671a507 commit ae62d1a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

hivemq-edge/src/main/java/com/hivemq/protocols/ProtocolAdapterWrapper.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,21 @@ private void stopAfterFailedStart() {
195195
if (writingEnabled && isWriting()) {
196196
final AtomicBoolean futureCompleted = new AtomicBoolean(false);
197197
final AtomicBoolean firstCallToStatusListener = new AtomicBoolean(true);
198-
final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
198+
final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(runnable -> {
199+
final Thread thread = new Thread(runnable);
200+
thread.setName("adapter-start-timeout-thread-" + adapter.getId());
201+
thread.setDaemon(false);
202+
return thread;
203+
});
199204
final long startTime = System.currentTimeMillis();
200-
final ScheduledFuture<?> scheduledFuture = scheduler.scheduleWithFixedDelay(() -> {
205+
final ScheduledFuture<?> scheduledFuture = scheduler.schedule(() -> {
201206
if (((System.currentTimeMillis() - startTime) > (WRITE_FUTURE_COMPLETE_DELAY - 1) * 1000) &&
202207
futureCompleted.compareAndSet(false, true)) {
203208
log.error("Protocol adapter with id {} start writing failed because of timeout.",
204209
adapter.getId());
205210
future.complete(false);
206211
}
207-
}, WRITE_FUTURE_COMPLETE_DELAY, WRITE_FUTURE_COMPLETE_DELAY, TimeUnit.SECONDS);
212+
}, WRITE_FUTURE_COMPLETE_DELAY, TimeUnit.SECONDS);
208213
future.thenAccept(success -> {
209214
if (!scheduledFuture.isCancelled()) {
210215
scheduledFuture.cancel(true);

0 commit comments

Comments
 (0)