Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
SkyWalking
提交
e03e9f25
S
SkyWalking
项目概览
apache
/
SkyWalking
上一次同步 1 年多
通知
302
Star
21345
Fork
6091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
e03e9f25
编写于
2月 24, 2016
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
补充#31部分代码。修复边界BUG。并提交更合理的测试用例。
上级
921ea272
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
16 deletion
+18
-16
skywalking-protocol/src/main/java/com/ai/cloud/skywalking/util/AtomicRangeInteger.java
...java/com/ai/cloud/skywalking/util/AtomicRangeInteger.java
+7
-7
skywalking-protocol/src/test/java/test/ai/cloud/skywalking/util/AtomicRangeIntegerTest.java
...test/ai/cloud/skywalking/util/AtomicRangeIntegerTest.java
+11
-9
未找到文件。
skywalking-protocol/src/main/java/com/ai/cloud/skywalking/util/AtomicRangeInteger.java
浏览文件 @
e03e9f25
...
...
@@ -21,11 +21,14 @@ public class AtomicRangeInteger extends Number implements java.io.Serializable {
*
* @param initialValue
* the initial value
* @param endValue
*
* AtomicRangeInteger在startValue和maxValue循环取值( startValue <= value < maxValue)
*/
public
AtomicRangeInteger
(
int
startValue
,
int
end
Value
)
{
public
AtomicRangeInteger
(
int
startValue
,
int
max
Value
)
{
value
=
new
AtomicInteger
(
startValue
);
this
.
startValue
=
startValue
;
this
.
endValue
=
endValue
;
this
.
endValue
=
maxValue
-
1
;
}
/**
...
...
@@ -35,11 +38,8 @@ public class AtomicRangeInteger extends Number implements java.io.Serializable {
*/
public
final
int
getAndIncrement
()
{
for
(;;)
{
int
current
=
get
();
int
next
=
current
+
1
;
if
(
next
>=
this
.
endValue
)
{
next
=
this
.
startValue
;
}
int
current
=
value
.
get
();
int
next
=
current
>=
this
.
endValue
?
this
.
startValue
:
current
+
1
;
if
(
value
.
compareAndSet
(
current
,
next
))
return
current
;
}
...
...
skywalking-protocol/src/test/java/test/ai/cloud/skywalking/util/AtomicRangeIntegerTest.java
浏览文件 @
e03e9f25
...
...
@@ -9,6 +9,10 @@ import junit.framework.TestCase;
import
com.ai.cloud.skywalking.util.AtomicRangeInteger
;
public
class
AtomicRangeIntegerTest
extends
TestCase
{
static
String
[]
buffer
=
new
String
[
5000
];
static
AtomicRangeInteger
ari
=
new
AtomicRangeInteger
(
0
,
buffer
.
length
);
public
void
testGet
(){
AtomicRangeInteger
ari
=
new
AtomicRangeInteger
(
0
,
12
);
for
(
int
i
=
0
;
i
<
51
;
i
++){
...
...
@@ -36,22 +40,20 @@ public class AtomicRangeIntegerTest extends TestCase{
}
class
RangeIntegerThread
extends
Thread
{
private
static
String
[]
buffer
=
new
String
[
500000000
];
private
static
AtomicRangeInteger
ari
=
new
AtomicRangeInteger
(
0
,
buffer
.
length
);
@Override
public
void
run
(){
while
(
true
){
int
i
=
ari
.
getAndIncrement
();
int
i
=
AtomicRangeIntegerTest
.
ari
.
getAndIncrement
();
if
(
i
%
10000000
==
0
){
System
.
out
.
println
(
ari
.
get
());
System
.
out
.
println
(
AtomicRangeIntegerTest
.
ari
.
get
());
}
if
(
i
>=
buffer
.
length
-
100000
){
if
(
AtomicRangeIntegerTest
.
buffer
[
i
]
!=
null
){
System
.
out
.
println
(
"end at index:"
+
i
+
","
+
AtomicRangeIntegerTest
.
buffer
[
i
]);
break
;
}
else
{
System
.
out
.
println
(
"at index:"
+
i
);
AtomicRangeIntegerTest
.
buffer
[
i
]
=
"string"
;
}
Assert
.
assertNull
(
buffer
[
i
]);
buffer
[
i
]
=
"string"
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录