I am working on a web application where I need to generate a random number for each request. The request will hit a specific bucket from a set of buckets. The random numbers generated for a given bucket should have a uniform distribution. I am planning to use a map which has a SplittableRandom instances against bucket ids like this
buketId -> SplittableRandom
To entertain a web-request I first check the bucketId specified in the request. Then I select the corresponding SplittableRandom instance and call split() on it. Under heavy load split() method will be called on the same instance by multiple threads. Is this approach thread safe?
Aucun commentaire:
Enregistrer un commentaire