Skip to content

Commit

Permalink
Merge pull request quarkusio#29168 from geoand/exec-shutdown
Browse files Browse the repository at this point in the history
Ensure that some instances of ExecutorService are properly shutdown
  • Loading branch information
geoand authored Nov 10, 2022
2 parents 9108cfa + cdc35d4 commit f29b288
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
Expand Down Expand Up @@ -372,19 +373,33 @@ private static void s2iBuild(OpenShiftClient client, BuildConfig buildConfig, Fi
}

private static void waitForBuildComplete(OpenShiftClient client, S2iConfig s2iConfig, String buildName, Closeable watch) {
Executor executor = Executors.newSingleThreadExecutor();
CountDownLatch latch = new CountDownLatch(1);
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(() -> {
try {
client.builds().withName(buildName).waitUntilCondition(b -> !RUNNING.equalsIgnoreCase(b.getStatus().getPhase()),
s2iConfig.buildTimeout.toMillis(), TimeUnit.MILLISECONDS);
} finally {
try {
watch.close();
} catch (IOException e) {
LOG.debug("Error closing log reader.");
}
latch.countDown();
}
});
try {
latch.await();
} catch (InterruptedException e) {
LOG.debug("Error waiting for build to complete.", e);
} finally {
try {
watch.close();
} catch (IOException e) {
LOG.debug("Error closing log reader.", e);
}
try {
executor.shutdown();
} catch (Exception e) {
LOG.debug("Error shutting down executor", e);
}
}

}

public static Predicate<HasMetadata> distinctByResourceKey() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.quarkus.smallrye.reactivemessaging.runtime.devmode;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Supplier;

Expand All @@ -17,14 +17,19 @@ public class ReactiveMessagingHotReplacementSetup implements HotReplacementSetup

private HotReplacementContext context;
private volatile long nextUpdate;
private final Executor executor = Executors.newSingleThreadExecutor();
private final ExecutorService executor = Executors.newSingleThreadExecutor();

@Override
public void setupHotDeployment(HotReplacementContext context) {
this.context = context;
DevModeSupportConnectorFactoryInterceptor.register(new OnMessage());
}

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

private class OnMessage implements Supplier<CompletableFuture<Boolean>> {
@Override
public CompletableFuture<Boolean> get() {
Expand Down

0 comments on commit f29b288

Please sign in to comment.