Permalink
Browse files

Merge pull request #1023 from abracadv8/master

Avoid scheduling when DiscoveryClient.shutdown called (fix for #973)
  • Loading branch information...
2 parents 22e3345 + ef4f513 commit 05d5783d8c7a6e81dcab6265441c082dc96c23a0 @qiangdavidliu qiangdavidliu committed Dec 13, 2017
Showing with 14 additions and 2 deletions.
  1. +14 −2 eureka-client/src/main/java/com/netflix/discovery/InstanceInfoReplicator.java
@@ -6,6 +6,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
@@ -68,10 +69,21 @@ public void start(int initialDelayMs) {
}
public void stop() {
- scheduler.shutdownNow();
+ shutdownAndAwaitTermination(scheduler);
started.set(false);
}
+ private void shutdownAndAwaitTermination(ExecutorService pool) {
+ pool.shutdown();
+ try {
+ if (!pool.awaitTermination(3, TimeUnit.SECONDS)) {
+ pool.shutdownNow();
+ }
+ } catch (InterruptedException e) {
+ logger.warn("InstanceInfoReplicator stop interrupted");
+ }
+ }
+
public boolean onDemandUpdate() {
if (rateLimiter.acquire(burstSize, allowedRatePerMinute)) {
scheduler.submit(new Runnable() {
@@ -112,4 +124,4 @@ public void run() {
}
}
-}
+}

0 comments on commit 05d5783

Please sign in to comment.