Quick fix for shutdown race issue (#439)
* Added a synchronized lock in the initialize and shutdown methods
This commit is contained in:
parent
0326e217f6
commit
854e316b83
1 changed files with 60 additions and 54 deletions
|
|
@ -122,6 +122,8 @@ public class Scheduler implements Runnable {
|
||||||
private volatile long shutdownStartTimeMillis;
|
private volatile long shutdownStartTimeMillis;
|
||||||
private volatile boolean shutdownComplete = false;
|
private volatile boolean shutdownComplete = false;
|
||||||
|
|
||||||
|
private final Object lock = new Object();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to ensure that only one requestedShutdown is in progress at a time.
|
* Used to ensure that only one requestedShutdown is in progress at a time.
|
||||||
*/
|
*/
|
||||||
|
|
@ -222,6 +224,7 @@ public class Scheduler implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
|
synchronized (lock) {
|
||||||
workerStateChangeListener.onWorkerStateChange(WorkerStateChangeListener.WorkerState.INITIALIZING);
|
workerStateChangeListener.onWorkerStateChange(WorkerStateChangeListener.WorkerState.INITIALIZING);
|
||||||
boolean isDone = false;
|
boolean isDone = false;
|
||||||
Exception lastException = null;
|
Exception lastException = null;
|
||||||
|
|
@ -272,6 +275,7 @@ public class Scheduler implements Runnable {
|
||||||
}
|
}
|
||||||
workerStateChangeListener.onWorkerStateChange(WorkerStateChangeListener.WorkerState.STARTED);
|
workerStateChangeListener.onWorkerStateChange(WorkerStateChangeListener.WorkerState.STARTED);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void runProcessLoop() {
|
void runProcessLoop() {
|
||||||
|
|
@ -463,6 +467,7 @@ public class Scheduler implements Runnable {
|
||||||
* </ol>
|
* </ol>
|
||||||
*/
|
*/
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
|
synchronized (lock) {
|
||||||
if (shutdown) {
|
if (shutdown) {
|
||||||
log.warn("Shutdown requested a second time.");
|
log.warn("Shutdown requested a second time.");
|
||||||
return;
|
return;
|
||||||
|
|
@ -479,6 +484,7 @@ public class Scheduler implements Runnable {
|
||||||
leaseCoordinator.stop();
|
leaseCoordinator.stop();
|
||||||
workerStateChangeListener.onWorkerStateChange(WorkerStateChangeListener.WorkerState.SHUT_DOWN);
|
workerStateChangeListener.onWorkerStateChange(WorkerStateChangeListener.WorkerState.SHUT_DOWN);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform final shutdown related tasks for the worker including shutting down worker owned executor services,
|
* Perform final shutdown related tasks for the worker including shutting down worker owned executor services,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue