'ThreadLocalRandom' instance might be shared
Reports java.util.concurrent.ThreadLocalRandom
instances which might be shared between threads.
A ThreadLocalRandom
should not be shared between threads because that is not thread-safe. The inspection reports instances that are assigned to a field used as a method argument, or assigned to a local variable and used in anonymous or nested classes as they might get shared between threads.
Usages of ThreadLocalRandom
should typically look like ThreadLocalRandom.current().nextInt(...)
(or nextDouble(...)
etc.). When all usages are in this form, ThreadLocalRandom
instances cannot be used accidentally by multiple threads.
Example:
Use the options to list methods that are safe to be passed to ThreadLocalRandom
instances as an argument. It's possible to use regular expressions for method names.
Inspection options
Option | Type | Default |
---|---|---|
Table | None | |
Class Name | TableColumn | [java.math.BigInteger, java.util.Collections] |
Method Name Regex | TableColumn | [.*, shuffle] |
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |