Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup #1468 Intermittent failure of CamelDevModeTest #1483

Merged
merged 1 commit into from
Jul 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.camel.quarkus.main;

import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import io.quarkus.runtime.Quarkus;
import org.apache.camel.CamelContext;
Expand All @@ -32,6 +31,7 @@ public class CamelMainRuntime implements CamelRuntime {
private static final Logger LOGGER = LoggerFactory.getLogger(CamelMainRuntime.class);
private final CamelMain main;
private final long shutdownTimeoutMs;
private volatile Thread mainThread;

public CamelMainRuntime(CamelMain main, long shutdownTimeoutMs) {
this.main = main;
Expand All @@ -48,15 +48,17 @@ public void start(String[] args) {
main.parseArguments(args);
main.startEngine();

new Thread(() -> {
final Thread worker = new Thread(() -> {
try {
main.runEngine();
} catch (Exception e) {
LOGGER.error("Failed to start application", e);
stop();
throw new RuntimeException(e);
}
}, "camel-main").start();
}, "camel-main");
this.mainThread = worker;
worker.start();
} catch (Exception e) {
LOGGER.error("Failed to start application", e);
stop();
Expand All @@ -68,10 +70,13 @@ public void start(String[] args) {
public void stop() {
main.stop();
/* Wait till the Camel shutdown is finished in camel-main thread started in start(String[]) above */
try {
main.getShutdownStrategy().await(shutdownTimeoutMs, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
final Thread worker = this.mainThread;
if (worker != null) {
try {
worker.join(shutdownTimeoutMs);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}

Expand Down