Skip to content

Commit

Permalink
undo executorservice close
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Oct 27, 2023
1 parent dccbf78 commit 7487205
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public Map<String, Long> dataErrors() {

@Override
public void close() {
executor.close();
executor.shutdown();
push();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,33 @@ public Worker(String prefix, Stats stats, int threads, RunnableThatThrows task)
public Worker(String prefix, Stats stats, int threads, IntConsumerThatThrows task) {
this.prefix = prefix;
stats.gauge(prefix + "_threads", threads);
try (var es = Executors.newFixedThreadPool(threads, new NamedThreadFactory(prefix))) {
String parentStage = LogUtil.getStage();
List<CompletableFuture<?>> results = new ArrayList<>();
for (int i = 0; i < threads; i++) {
final int threadId = i;
results.add(CompletableFuture.runAsync(() -> {
LogUtil.setStage(parentStage, prefix);
String id = Thread.currentThread().getName();
LOGGER.trace("Starting worker");
try {
long start = System.nanoTime();
task.accept(threadId);
stats.timers().finishedWorker(prefix, Duration.ofNanos(System.nanoTime() - start));
} catch (Throwable e) {
System.err.println("Worker " + id + " died");
// when one worker dies it may close resources causing others to die as well, so only log the first
if (firstWorkerDied.compareAndSet(false, true)) {
e.printStackTrace(); // NOSONAR
}
throwFatalException(e);
} finally {
LOGGER.trace("Finished worker");
var es = Executors.newFixedThreadPool(threads, new NamedThreadFactory(prefix));
String parentStage = LogUtil.getStage();
List<CompletableFuture<?>> results = new ArrayList<>();
for (int i = 0; i < threads; i++) {
final int threadId = i;
results.add(CompletableFuture.runAsync(() -> {
LogUtil.setStage(parentStage, prefix);
String id = Thread.currentThread().getName();
LOGGER.trace("Starting worker");
try {
long start = System.nanoTime();
task.accept(threadId);
stats.timers().finishedWorker(prefix, Duration.ofNanos(System.nanoTime() - start));
} catch (Throwable e) {
System.err.println("Worker " + id + " died");
// when one worker dies it may close resources causing others to die as well, so only log the first
if (firstWorkerDied.compareAndSet(false, true)) {
e.printStackTrace(); // NOSONAR
}
}, es));
}
done = joinFutures(results);
throwFatalException(e);
} finally {
LOGGER.trace("Finished worker");
}
}, es));
}
es.shutdown();
done = joinFutures(results);
}

/**
Expand Down

0 comments on commit 7487205

Please sign in to comment.