Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;
Expand Down Expand Up @@ -322,7 +322,7 @@ private static void setProperties(int propertySize, List<Message> msgs) {
msg.getProperties().clear();
}

int startValue = (new Random(System.currentTimeMillis())).nextInt(100);
int startValue = ThreadLocalRandom.current().nextInt(100);
int size = 0;
for (int i = 0; ; i++) {
String prop1 = "prop" + i, prop1V = "hello" + startValue;
Expand Down Expand Up @@ -449,4 +449,4 @@ public void run() {
public void shutdown() {
executorService.shutdown();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Random;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicLong;

public class Producer {
Expand Down Expand Up @@ -197,7 +197,7 @@ public void run() {
msg.getProperties().clear();
}
int i = 0;
int startValue = (new Random(System.currentTimeMillis())).nextInt(100);
int startValue = ThreadLocalRandom.current().nextInt(100);
int size = 0;
while (true) {
String prop1 = "prop" + i, prop1V = "hello" + startValue;
Expand Down
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
<jacoco-maven-plugin.version>0.8.5</jacoco-maven-plugin.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<sonar-maven-plugin.version>3.0.2</sonar-maven-plugin.version>
<spotbugs-plugin.version>4.2.2</spotbugs-plugin.version>
<spotbugs-plugin.version>4.8.6.8</spotbugs-plugin.version>
<maven-assembly-plugin.version>3.4.2</maven-assembly-plugin.version>
<maven-javadoc-plugin.version>2.10.4</maven-javadoc-plugin.version>
<maven-failsafe-plugin.version>2.19.1</maven-failsafe-plugin.version>
Expand Down Expand Up @@ -451,7 +451,6 @@
<configuration>
<failOnError>true</failOnError>
<fork>false</fork>
<spotbugsXmlOutput>true</spotbugsXmlOutput>
<excludeFilterFile>${project.root}/style/spotbugs-suppressions.xml</excludeFilterFile>
<threshold>High</threshold>
<effort>Max</effort>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
Expand Down Expand Up @@ -67,9 +67,8 @@ public MessageQueueSelector(TopicRouteWrapper topicRouteWrapper, boolean read,
this.queues.addAll(buildWrite(topicRouteWrapper));
}
buildBrokerActingQueues(topicRouteWrapper.getTopicName(), this.queues);
Random random = new Random();
this.queueIndex = new AtomicInteger(random.nextInt());
this.brokerIndex = new AtomicInteger(random.nextInt());
this.queueIndex = new AtomicInteger(ThreadLocalRandom.current().nextInt());
this.brokerIndex = new AtomicInteger(ThreadLocalRandom.current().nextInt());

if (priorityProvider == null) {
priorityProvider = new DefaultMessageQueuePriorityProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -180,8 +180,7 @@ public NettyRemotingClient(final NettyClientConfig nettyClientConfig,
}

private static int initValueIndex() {
Random r = new Random();
return r.nextInt(999);
return ThreadLocalRandom.current().nextInt(999);
}

private void loadSocksProxyJson() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import org.apache.rocketmq.common.ThreadFactoryImpl;
import org.apache.rocketmq.common.TopicConfig;
Expand Down Expand Up @@ -149,7 +149,7 @@ private CompactionLog loadAndGetClog(String topic, int queueId) {
try {
v = new CompactionLog(defaultMessageStore, this, topic, queueId);
v.load(true);
int randomDelay = 1000 + new Random(System.currentTimeMillis()).nextInt(compactionInterval);
int randomDelay = 1000 + ThreadLocalRandom.current().nextInt(compactionInterval);
compactionSchedule.scheduleWithFixedDelay(v::doCompaction, compactionInterval + randomDelay, compactionInterval + randomDelay, TimeUnit.MILLISECONDS);
} catch (IOException e) {
log.error("create compactionLog exception: ", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ public static int[] getRandomArray(int min, int max, int n) {
}

int[] result = new int[n];
Random rd = new Random();
int index = 0;
for (int i = 0; i < result.length; i++) {
index = rd.nextInt(len--);
Expand Down
Loading