Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion to add a static method to generate a random based UUID using ThreadLocalRandom (requires JDK 7) #39

Open
tehnic-take3 opened this issue Apr 6, 2021 · 6 comments

Comments

@tehnic-take3
Copy link

I suggest to add a static method like the following to UUIDUtil (or any other appropriate class):

public static UUID generateThreadLocalRandomUUID() {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
return UUIDUtil.constructUUID(UUIDType.RANDOM_BASED, rnd.nextLong(), rnd.nextLong());
}

Using a generator created by Generators.randomBasedGenerator(ThreadLocalRandom.current()) is probably not a good idea when working in an environment with thread pools (like Java/Jakarta EE), so i came to this solution.

Best regards, Robert

@cowtowncoder
Copy link
Owner

Hi there! Thank you for the suggestion!

I'll have to think about this a bit wrt API; and also see what is the minimum JDK expectation (ThreadLocalRandom seems to have been added in Java 1.7/7).

@agentgt
Copy link

agentgt commented Mar 2, 2022

Sort of orthogonal but If the required JVM version is bumped to 9 or later I recommend you use System.Logger instead of SLF4J.

To be honest I'm surprised this library uses logging.

@cowtowncoder
Copy link
Owner

cowtowncoder commented Mar 3, 2022

I doubt there's much point in bumping minimum JDK past 8 in near future.

As to logging, yes it is not used for regular operation (definitely not on per-uuid-generated basis) but for some specific failure condition... I'd have to check it but I think it was for file-backed locking, if used to store state across invocations (last "reserved" timestamp from time/location based variant).

You can also follow discussions wrt evolution of logging dependency, f.ex #32.

@cowtowncoder cowtowncoder changed the title Suggestion to add a static method to generate a random based UUID using ThreadLocalRandom Suggestion to add a static method to generate a random based UUID using ThreadLocalRandom (requires JDK 7) Jun 18, 2022
@cowtowncoder
Copy link
Owner

Ok, couple of notes:

  • UUIDUtil is probably not an optimal place (although I guess I could). But maybe rather add straight into Generators
  • Or, could perhaps figure out a way to encapsulate things to allow proper generator instance that hides access?
  • ... alas, Jug 4.x is still Java 6 and ThreadLocalRandom seems to JDK 7 addition.

The last point would keep this out of 4.0.x. But if we were to increase JDK baseline to 8 that wouldn't be a problem.
Besides although java source/target is defined as 1.6, I am not 100% sure there might not already be accidental JDK 7 dependencies.

Still, I need to think about this a bit now.

@cowtowncoder
Copy link
Owner

Note: #53 is for increasing baseline to JDK 8

@cowtowncoder
Copy link
Owner

And now that #53 merged this could proceed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants