1. 修复unusedServerAddresses的数量小于等于1的情况,使用ThreadLocalRandom会抛出异常

This commit is contained in:
ascrutae 2016-02-24 19:35:03 +08:00
parent 8f01480b95
commit 2e8425117c
1 changed files with 8 additions and 2 deletions

View File

@ -197,8 +197,14 @@ public class DataSenderFactoryWithBalance {
private static DataSender findReadySender() {
DataSender result = null;
int index = ThreadLocalRandom.current().nextInt(0,
unusedServerAddresses.size());
int index = 0;
if (unusedServerAddresses.size() > 1){
index = ThreadLocalRandom.current().nextInt(0,
unusedServerAddresses.size());
}
for (int i = 0; i < unusedServerAddresses.size(); i++, index++) {
if (index == unusedServerAddresses.size()) {