summaryrefslogtreecommitdiffstats
path: root/container-disc
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-03-01 10:34:29 +0100
committerJon Bratseth <bratseth@oath.com>2018-03-01 10:34:29 +0100
commit9ee6394e974bc2e7e233cb9ddd29d684297959da (patch)
tree054b09f21d1546e07ec964210e7ae6b4f1d16c46 /container-disc
parent60752add2a2bc93a0ca7377b51abe2a2584f1fd0 (diff)
Make more effort to not die at the same time
Diffstat (limited to 'container-disc')
-rw-r--r--container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java8
1 files changed, 7 insertions, 1 deletions
diff --git a/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java b/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java
index f5a8f598a94..b2784dfef60 100644
--- a/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java
+++ b/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java
@@ -7,6 +7,7 @@ import com.yahoo.container.di.ComponentDeconstructor;
import com.yahoo.container.di.componentgraph.Provider;
import com.yahoo.jdisc.SharedResource;
+import java.security.SecureRandom;
import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -60,6 +61,11 @@ public class Deconstructor implements ComponentDeconstructor {
this.component = component;
}
+ /** Returns a random value which will be different across identical containers invoking this at the same time */
+ private long random() {
+ return new SecureRandom().nextLong();
+ }
+
public void run() {
log.info("Starting deconstruction of " + component);
try {
@@ -72,7 +78,7 @@ public class Deconstructor implements ComponentDeconstructor {
catch (Error e) {
try {
// Randomize restart over 10 minutes to avoid simultaneous cluster restarts
- Thread.sleep((long) (new Random(System.nanoTime()).nextDouble() * 1000 * 60 * 10));
+ Thread.sleep(random() * 1000 * 60 * 10);
}
catch (InterruptedException exception) {
log.log(WARNING, "Randomized wait before dying disrupted. Dying now.");