apache / apache/iotdb

Replace `new Random()` with `ThreadLocalRandom`

Open
#6,142 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
6.4k
Forks
1.2k
Avg merge
1d 23h
Merged PRs (30d)
115

Description

`ThreadLocalRandom` provides better performance than `Random`. I think we should replace the `Random` class except test files or example files.

I search the project files, the `Random` class in the following class or method should be replaced:

- Method: `org.apache.iotdb.influxdb.session.InfluxDBSession#reconnect`
- Class: `org.apache.iotdb.cluster.log.snapshot.PullSnapshotTask`
- Class: `org.apache.iotdb.cluster.server.heartbeat.HeartbeatThread`
- Abstract Class: `org.apache.iotdb.cluster.server.member.RaftMember`
- Class: `org.apache.iotdb.db.engine.modification.ModificationFile`
- Class: `org.apache.iotdb.db.engine.storagegroup.TsFileResource`
- Method: `org.apache.iotdb.db.service.thrift.impl.InternalServiceImpl#getHeartBeat`
- Method: `org.apache.iotdb.session.SessionConnection#reconnect`
- Class: `org.apache.iotdb.library.dprofile.UDTFSample`
- Class: `org.apache.iotdb.commons.udf.builtin.UDTFEqualSizeBucketRandomSample`

Related issue: #5880

Contributor guide

Open the contributing guide

Research direction

Locate the listed Java classes and methods, including InfluxDBSession#reconnect, PullSnapshotTask, HeartbeatThread, RaftMember, ModificationFile, TsFileResource, InternalServiceImpl#getHeartBeat, SessionConnection#reconnect, UDTFSample, and UDTFEqualSizeBucketRandomSample. Review each production use of Random, excluding test and example files. Done means the listed eligible usages use ThreadLocalRandom and the related issue #5880 remains consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, databases
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.