From 1826fd960e5d24ed82ed29af520ec7c376d1dbab Mon Sep 17 00:00:00 2001 From: Fabio Lima Date: Wed, 8 Apr 2020 19:02:25 -0300 Subject: [PATCH] Updated UlidBasedGuidCreator --- .../ulid/creator/UlidBasedGuidCreator.java | 36 +------------------ 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/src/main/java/com/github/f4b6a3/ulid/creator/UlidBasedGuidCreator.java b/src/main/java/com/github/f4b6a3/ulid/creator/UlidBasedGuidCreator.java index 26641b6..febe3e1 100644 --- a/src/main/java/com/github/f4b6a3/ulid/creator/UlidBasedGuidCreator.java +++ b/src/main/java/com/github/f4b6a3/ulid/creator/UlidBasedGuidCreator.java @@ -26,7 +26,6 @@ package com.github.f4b6a3.ulid.creator; import java.util.Random; import java.util.UUID; -import java.util.concurrent.ThreadLocalRandom; import com.github.f4b6a3.ulid.timestamp.TimestampStrategy; import com.github.f4b6a3.ulid.util.UlidUtil; @@ -57,8 +56,6 @@ public class UlidBasedGuidCreator { protected Random random; - protected boolean useThreadLocal = false; - protected static final String OVERRUN_MESSAGE = "The system overran the generator by requesting too many GUIDs."; protected TimestampStrategy timestampStrategy; @@ -172,10 +169,7 @@ public class UlidBasedGuidCreator { protected synchronized void reset() { // Get random values - if (useThreadLocal) { - this.randomMsb = truncate(ThreadLocalRandom.current().nextLong()); - this.randomLsb = truncate(ThreadLocalRandom.current().nextLong()); - } else if (random == null) { + if (random == null) { this.randomMsb = truncate(RandomUtil.get().nextLong()); this.randomLsb = truncate(RandomUtil.get().nextLong()); } else { @@ -231,12 +225,7 @@ public class UlidBasedGuidCreator { */ @SuppressWarnings("unchecked") public synchronized T withRandomGenerator(Random random) { - this.random = random; - - // disable thread local - this.useThreadLocal = false; - return (T) this; } @@ -253,31 +242,8 @@ public class UlidBasedGuidCreator { */ @SuppressWarnings("unchecked") public synchronized T withFastRandomGenerator() { - final int salt = (int) FingerprintUtil.getFingerprint(); this.random = new Xorshift128PlusRandom(salt); - - // disable thread local - this.useThreadLocal = false; - - return (T) this; - } - - /** - * Replaces the default random generator with ThreadLocalRandom. - * - * See {@link java.util.concurrent.ThreadLocalRandom} - * - * @return {@link RandomUuidCreator} - */ - @SuppressWarnings("unchecked") - public synchronized T withThreadLocalRandomGenerator() { - - this.useThreadLocal = true; - - // remove random instance - this.random = null; - return (T) this; }