From b4bc47e280d6f83f33fcc9b78684d01bfdbeb8fc Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 25 Apr 2014 17:42:00 +0900 Subject: [PATCH] Code clean-up Motivation: It is less confusing not to spread Thread.interrupt() calls. Modification: - Comments - Move generatorThread.interrupt() to where currentThread.interrupt() is triggered Result: Code that is easier to read --- .../java/io/netty/util/internal/ThreadLocalRandom.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/io/netty/util/internal/ThreadLocalRandom.java b/common/src/main/java/io/netty/util/internal/ThreadLocalRandom.java index d9f7de5a00..4413025370 100644 --- a/common/src/main/java/io/netty/util/internal/ThreadLocalRandom.java +++ b/common/src/main/java/io/netty/util/internal/ThreadLocalRandom.java @@ -131,7 +131,6 @@ public class ThreadLocalRandom extends Random { } } catch (InterruptedException e) { interrupted = true; - generatorThread.interrupt(); logger.warn("Failed to generate a seed from SecureRandom due to an InterruptedException."); break; } @@ -144,8 +143,12 @@ public class ThreadLocalRandom extends Random { ThreadLocalRandom.initialSeedUniquifier = initialSeedUniquifier; if (interrupted) { - // restore interrupt status because we don't know how to/don't need to handle it here + // Restore the interrupt status because we don't know how to/don't need to handle it here. Thread.currentThread().interrupt(); + + // Interrupt the generator thread if it's still running, + // in the hope that the SecureRandom provider raises an exception on interruption. + generatorThread.interrupt(); } }