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

Save and re-use this "Random". #5880

Open
MinaQin opened this issue May 12, 2022 · 2 comments
Open

Save and re-use this "Random". #5880

MinaQin opened this issue May 12, 2022 · 2 comments
Assignees

Comments

@MinaQin
Copy link
Contributor

MinaQin commented May 12, 2022

Code Path: confignode/src/main/java/org/apache/iotdb/confignode/manager/PartitionManager.java
image
Creating a new Random object each time a random value is needed is inefficient and may produce numbers which are not random depending on the JDK. For better efficiency and randomness, create a single Random, then store, and reuse it.

The Random() constructor tries to set the seed with a distinct value every time. However there is no guarantee that the seed will be random or even uniformly distributed. Some JDK will use the current time as seed, which makes the generated numbers not random at all.

This rule finds cases where a new Random is created each time a method is invoked.

@azhsmesos
Copy link

My idea is to add a cache to store random. If this idea is possible, please assigned it to me

@azhsmesos
Copy link

thank you

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

No branches or pull requests

3 participants