Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈文顺
discovery
Commits
02ac02b3
Commit
02ac02b3
authored
Aug 13, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化成ThreadLocalRandom
parent
2fac9dae
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
4 deletions
+2
-4
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/decorator/ZoneAvoidanceRuleDecorator.java
+2
-4
No files found.
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/decorator/ZoneAvoidanceRuleDecorator.java
View file @
02ac02b3
...
...
@@ -11,7 +11,7 @@ package com.nepxion.discovery.plugin.framework.decorator;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.
concurrent.ThreadLocal
Random
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.MapUtils
;
...
...
@@ -35,8 +35,6 @@ public class ZoneAvoidanceRuleDecorator extends ZoneAvoidanceRule {
@Autowired
private
PluginAdapter
pluginAdapter
;
private
final
Random
random
=
new
Random
();
@Override
public
Server
choose
(
Object
key
)
{
RuleEntity
ruleEntity
=
pluginAdapter
.
getRule
();
...
...
@@ -112,7 +110,7 @@ public class ZoneAvoidanceRuleDecorator extends ZoneAvoidanceRule {
}
// 获取介于0(含)和n(不含)伪随机,均匀分布的int值
int
hitWeight
=
random
.
nextInt
(
totalWeight
)
+
1
;
// [1, totalWeight)
int
hitWeight
=
ThreadLocalRandom
.
current
()
.
nextInt
(
totalWeight
)
+
1
;
// [1, totalWeight)
for
(
int
i
=
0
;
i
<
weightHolder
.
length
;
i
++)
{
if
(
hitWeight
<=
weightHolder
[
i
][
1
])
{
return
weightHolder
[
i
][
0
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment