Skip to content

Commit

Permalink
Add comments to the HTTPServer start() method
Browse files Browse the repository at this point in the history
Signed-off-by: Fabian Stäber <fabian@fstab.de>
  • Loading branch information
fstab committed May 15, 2024
1 parent dfc559d commit 2ae979d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static void main(String[] args) throws IOException, InterruptedException
.buildAndStart();

System.out.println("HTTPServer listening on port http://localhost:" + server.getPort() + "/metrics");
Thread.sleep(10_000);
Thread.currentThread().join(); // wait forever
}

private static int parsePortOrExit(String port) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ private HTTPServer(PrometheusProperties config, ExecutorService executorService,
registerHandler("/metrics", new MetricsHandler(config, registry), authenticator);
registerHandler("/-/healthy", new HealthyHandler(), authenticator);
try {
executorService.submit(() -> this.server.start()).get();
// HttpServer.start() starts the HttpServer in a new background thread.
// If we call HttpServer.start() from a thread of the executorService,
// the background thread will inherit the "daemon" property,
// i.e. the server will run as a Daemon thread.
// See https://github.com/prometheus/client_java/pull/955
this.executorService.submit(this.server::start).get();
// calling .get() on the Future here to avoid silently discarding errors
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
Expand Down

0 comments on commit 2ae979d

Please sign in to comment.