Skip to content

Commit 4f64a6c

Browse files
marcelmaybrian-brazil
authored andcommitted
Shutdown executor service to avoid non-daemon threads potentially blocking exiting JVMs. (#303)
1 parent f195003 commit 4f64a6c

File tree

1 file changed

+5
-1
lines changed
  • simpleclient_httpserver/src/main/java/io/prometheus/client/exporter

1 file changed

+5
-1
lines changed

simpleclient_httpserver/src/main/java/io/prometheus/client/exporter/HTTPServer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.List;
1313
import java.util.Set;
1414
import java.util.HashSet;
15+
import java.util.concurrent.ExecutorService;
1516
import java.util.concurrent.Executors;
1617
import java.util.zip.GZIPOutputStream;
1718

@@ -108,6 +109,7 @@ protected static Set<String> parseQuery(String query) throws IOException {
108109
}
109110

110111
protected HttpServer server;
112+
protected final ExecutorService executorService;
111113

112114

113115
/**
@@ -119,7 +121,8 @@ public HTTPServer(InetSocketAddress addr, CollectorRegistry registry) throws IOE
119121
HttpHandler mHandler = new HTTPMetricHandler(registry);
120122
server.createContext("/", mHandler);
121123
server.createContext("/metrics", mHandler);
122-
server.setExecutor(Executors.newFixedThreadPool(5));
124+
executorService = Executors.newFixedThreadPool(5);
125+
server.setExecutor(executorService);
123126
server.start();
124127
}
125128

@@ -142,6 +145,7 @@ public HTTPServer(String host, int port) throws IOException {
142145
*/
143146
public void stop() {
144147
server.stop(0);
148+
executorService.shutdown(); // Free any (parked/idle) threads in pool
145149
}
146150
}
147151

0 commit comments

Comments
 (0)