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 boolean shutdownComplete = false;
|
||||
|
||||
private final Object lock = new Object();
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
synchronized (lock) {
|
||||
workerStateChangeListener.onWorkerStateChange(WorkerStateChangeListener.WorkerState.INITIALIZING);
|
||||
boolean isDone = false;
|
||||
Exception lastException = null;
|
||||
|
|
@ -272,6 +275,7 @@ public class Scheduler implements Runnable {
|
|||
}
|
||||
workerStateChangeListener.onWorkerStateChange(WorkerStateChangeListener.WorkerState.STARTED);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void runProcessLoop() {
|
||||
|
|
@ -463,6 +467,7 @@ public class Scheduler implements Runnable {
|
|||
* </ol>
|
||||
*/
|
||||
public void shutdown() {
|
||||
synchronized (lock) {
|
||||
if (shutdown) {
|
||||
log.warn("Shutdown requested a second time.");
|
||||
return;
|
||||
|
|
@ -479,6 +484,7 @@ public class Scheduler implements Runnable {
|
|||
leaseCoordinator.stop();
|
||||
workerStateChangeListener.onWorkerStateChange(WorkerStateChangeListener.WorkerState.SHUT_DOWN);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform final shutdown related tasks for the worker including shutting down worker owned executor services,
|
||||
|
|
|
|||
Loading…
Reference in a new issue