From e1a42e4ec756245b54026c25ff9f736fbffed1c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8A=E4=B8=80?= Date: Fri, 1 Dec 2017 19:57:52 +0800 Subject: [PATCH] Fix random int bug in SelectMessageQueueByRandom MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Author: 释一 Closes #173 from swwlqw/master. --- ...eueByRandoom.java => SelectMessageQueueByRandom.java} | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) rename client/src/main/java/org/apache/rocketmq/client/producer/selector/{SelectMessageQueueByRandoom.java => SelectMessageQueueByRandom.java} (85%) diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByRandoom.java b/client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByRandom.java similarity index 85% rename from client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByRandoom.java rename to client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByRandom.java index 4e9a92d2..070fcc3e 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByRandoom.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/selector/SelectMessageQueueByRandom.java @@ -22,17 +22,12 @@ import org.apache.rocketmq.client.producer.MessageQueueSelector; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.common.message.MessageQueue; -public class SelectMessageQueueByRandoom implements MessageQueueSelector { +public class SelectMessageQueueByRandom implements MessageQueueSelector { private Random random = new Random(System.currentTimeMillis()); @Override public MessageQueue select(List mqs, Message msg, Object arg) { - int value = random.nextInt(); - if (value < 0) { - value = Math.abs(value); - } - - value = value % mqs.size(); + int value = random.nextInt(mqs.size()); return mqs.get(value); } } -- GitLab