Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Can IcicleIdGenerator be used as a singleton? #9

Closed
vijayrawatsan opened this issue Sep 29, 2015 · 6 comments
Closed

Can IcicleIdGenerator be used as a singleton? #9

vijayrawatsan opened this issue Sep 29, 2015 · 6 comments

Comments

@vijayrawatsan
Copy link

No description provided.

@nathankleyn
Copy link
Contributor

@vijayrawatsan There's no reason why you can't create an instance of IcicleIdGenerator and wrap it in a singleton. However as it stands, IcicleIdGenerator does not offer any singleton interface to itself currently. This is primarily a design decision we took to eliminate as many forms of global state in our applications as possible.

@vijayrawatsan
Copy link
Author

My question indirectly was, is it thread safe? Can multiple objects safely call generateId simlutaneously?

@nathankleyn
Copy link
Contributor

@vijayrawatsan I believe IcicleIdGenerator itself is thread safe, although looking at RoundRobinRedisPool I suspect getNextRedis is not and would need some change to make it so. I'll raise a PR shortly that will make that particular case thread-safe, but there may be others. Any contributions to investigate and make the library thread-safe in this manner are very welcome!

@nathankleyn
Copy link
Contributor

@vijayrawatsan New version is being pushed as v1.1.1 with the thread-safety fix for RoundRobinRedisPool, should be available on Maven Central shortly for you. Let us know if you spot any other thread-safety issues!

@vijayrawatsan
Copy link
Author

@nathankleyn I did check IcicleIdGenerator it was looking thread-safe.
Also i just checked getNextRedis method looks thread-safe to me.

@nathankleyn
Copy link
Contributor

@vijayrawatsan Awesome! Let us know if you run into any issues - I'll close this ticket for now but feel free to open again if you hit a snag!

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

No branches or pull requests

2 participants