Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿啄debugIT
transmittable-thread-local
提交
4a9eb502
T
transmittable-thread-local
项目概览
阿啄debugIT
/
transmittable-thread-local
与 Fork 源项目一致
从无法访问的项目Fork
通知
8
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
transmittable-thread-local
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4a9eb502
编写于
6月 23, 2017
作者:
oldratlee
🔥
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code cleanup for AgentCheck
上级
044f4d0b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
15 deletion
+30
-15
src/test/java/com/alibaba/ttl/threadpool/agent/AgentCheck.java
...est/java/com/alibaba/ttl/threadpool/agent/AgentCheck.java
+30
-15
未找到文件。
src/test/java/com/alibaba/ttl/threadpool/agent/AgentCheck.java
浏览文件 @
4a9eb502
...
@@ -7,8 +7,11 @@ import com.alibaba.ttl.testmodel.Task;
...
@@ -7,8 +7,11 @@ import com.alibaba.ttl.testmodel.Task;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.ScheduledFuture
;
import
java.util.concurrent.ScheduledFuture
;
import
java.util.concurrent.ScheduledThreadPoolExecutor
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
static
com
.
alibaba
.
ttl
.
Utils
.
CHILD
;
import
static
com
.
alibaba
.
ttl
.
Utils
.
CHILD
;
...
@@ -24,37 +27,49 @@ import static com.alibaba.ttl.Utils.expandThreadPool;
...
@@ -24,37 +27,49 @@ import static com.alibaba.ttl.Utils.expandThreadPool;
* @author Jerry Lee (oldratlee at gmail dot com)
* @author Jerry Lee (oldratlee at gmail dot com)
*/
*/
public
final
class
AgentCheck
{
public
final
class
AgentCheck
{
static
ExecutorService
executorService
=
Executors
.
newFixedThreadPool
(
3
);
static
ScheduledExecutorService
scheduledExecutorService
=
Executors
.
newScheduledThreadPool
(
3
);
private
AgentCheck
()
{
private
AgentCheck
()
{
throw
new
InstantiationError
(
"Must not instantiate this class"
);
throw
new
InstantiationError
(
"Must not instantiate this class"
);
}
static
{
expandThreadPool
(
executorService
);
expandThreadPool
(
scheduledExecutorService
);
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
try
{
try
{
ThreadPoolExecutor
executorService
=
new
ThreadPoolExecutor
(
3
,
3
,
3L
,
TimeUnit
.
SECONDS
,
new
LinkedBlockingQueue
<
Runnable
>());
ScheduledThreadPoolExecutor
scheduledExecutorService
=
new
ScheduledThreadPoolExecutor
(
3
);
expandThreadPool
(
executorService
);
expandThreadPool
(
scheduledExecutorService
);
ConcurrentMap
<
String
,
TransmittableThreadLocal
<
String
>>
ttlInstances
=
createTestTtlValue
();
ConcurrentMap
<
String
,
TransmittableThreadLocal
<
String
>>
ttlInstances
=
createTestTtlValue
();
checkExecutorService
(
ttlInstances
);
checkExecutorService
(
executorService
,
ttlInstances
);
checkScheduledExecutorService
(
ttlInstances
);
checkScheduledExecutorService
(
scheduledExecutorService
,
ttlInstances
);
System
.
out
.
println
();
System
.
out
.
println
();
System
.
out
.
println
(
"===================================="
);
System
.
out
.
println
(
"===================================="
);
System
.
out
.
println
(
"OK!"
);
System
.
out
.
println
(
"
Check
OK!"
);
System
.
out
.
println
(
"===================================="
);
System
.
out
.
println
(
"===================================="
);
}
finally
{
executorService
.
shutdown
();
executorService
.
shutdown
();
scheduledExecutorService
.
shutdown
();
scheduledExecutorService
.
shutdown
();
executorService
.
awaitTermination
(
3
,
TimeUnit
.
MINUTES
);
scheduledExecutorService
.
awaitTermination
(
3
,
TimeUnit
.
MINUTES
);
if
(!
executorService
.
awaitTermination
(
3
,
TimeUnit
.
SECONDS
))
{
System
.
out
.
println
(
"Fail to close ThreadPoolExecutor"
);
System
.
exit
(
1
);
}
if
(!
scheduledExecutorService
.
awaitTermination
(
3
,
TimeUnit
.
SECONDS
))
{
System
.
out
.
println
(
"Fail to close scheduledExecutorService"
);
System
.
exit
(
1
);
}
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
System
.
exit
(
2
);
}
}
}
}
static
void
checkExecutorService
(
ConcurrentMap
<
String
,
TransmittableThreadLocal
<
String
>>
ttlInstances
)
throws
Exception
{
private
static
void
checkExecutorService
(
ExecutorService
executorService
,
ConcurrentMap
<
String
,
TransmittableThreadLocal
<
String
>>
ttlInstances
)
throws
Exception
{
Task
task
=
new
Task
(
"1"
,
ttlInstances
);
Task
task
=
new
Task
(
"1"
,
ttlInstances
);
executorService
.
submit
(
task
);
executorService
.
submit
(
task
);
...
@@ -82,7 +97,7 @@ public final class AgentCheck {
...
@@ -82,7 +97,7 @@ public final class AgentCheck {
);
);
}
}
static
void
checkScheduledExecutorService
(
ConcurrentMap
<
String
,
TransmittableThreadLocal
<
String
>>
ttlInstances
)
throws
Exception
{
private
static
void
checkScheduledExecutorService
(
ScheduledExecutorService
scheduledExecutorService
,
ConcurrentMap
<
String
,
TransmittableThreadLocal
<
String
>>
ttlInstances
)
throws
Exception
{
Task
task
=
new
Task
(
"2"
,
ttlInstances
);
Task
task
=
new
Task
(
"2"
,
ttlInstances
);
ScheduledFuture
<?>
future
=
scheduledExecutorService
.
schedule
(
task
,
200
,
TimeUnit
.
MILLISECONDS
);
ScheduledFuture
<?>
future
=
scheduledExecutorService
.
schedule
(
task
,
200
,
TimeUnit
.
MILLISECONDS
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录