Skip to content

Commit

Permalink
Fix random int bug in SelectMessageQueueByRandom
Browse files Browse the repository at this point in the history
Author: 释一 <quanwei.lqw@alibaba-inc.com>

Closes alibaba#173 from swwlqw/master.
  • Loading branch information
释一 authored and zhouxinyu committed Dec 1, 2017
1 parent 81884c8 commit e1a42e4
Showing 1 changed file with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,12 @@
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<MessageQueue> 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);
}
}

0 comments on commit e1a42e4

Please sign in to comment.