mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-13 08:25:26 +00:00
don't hang the main thread, keep a different, non daemon thread alive till we shutdown
This commit is contained in:
parent
5d8d2cf4f9
commit
d0a6342360
@ -54,7 +54,9 @@ public class Bootstrap {
|
|||||||
|
|
||||||
private Node node;
|
private Node node;
|
||||||
|
|
||||||
private static Thread keepAliveThread;
|
private static volatile Thread keepAliveThread;
|
||||||
|
|
||||||
|
private static volatile CountDownLatch keepAliveLatch;
|
||||||
|
|
||||||
private void setup(boolean addShutdownHook, Tuple<Settings, Environment> tuple) throws Exception {
|
private void setup(boolean addShutdownHook, Tuple<Settings, Environment> tuple) throws Exception {
|
||||||
tuple = setupJmx(tuple);
|
tuple = setupJmx(tuple);
|
||||||
@ -169,18 +171,18 @@ public class Bootstrap {
|
|||||||
System.err.close();
|
System.err.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
keepAliveLatch = new CountDownLatch(1);
|
||||||
// keep this thread alive (non daemon thread) until we shutdown
|
// keep this thread alive (non daemon thread) until we shutdown
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
latch.countDown();
|
keepAliveLatch.countDown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
keepAliveThread = new Thread(new Runnable() {
|
keepAliveThread = new Thread(new Runnable() {
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
try {
|
try {
|
||||||
latch.await();
|
keepAliveLatch.await();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// bail out
|
// bail out
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user