1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import
java.util.concurrent.ExecutorService;
import
java.util.concurrent.Executors;
/**
* 一个最简单的线程池,这个模型很简单,但是很有用
*
* @author leizhimin 2014/8/22 20:21
*/
public
class
Test3 {
private
static
final
ExecutorService threadPool = Executors.newFixedThreadPool(
1
);
public
static
void
main(String[] args)
throws
InterruptedException {
for
(
int
i =
0
; i <
10000
; i++) {
final
int
finalI = i;
Runnable r =
new
Runnable() {
@Override
public
void
run() {
System.out.println(String.valueOf(finalI)+
":"
+System.currentTimeMillis());
}
};
threadPool.submit(r);
Thread.currentThread().sleep(300L);
}
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
0
:
1409187082455
1
:
1409187082755
2
:
1409187083055
3
:
1409187083355
4
:
1409187083655
5
:
1409187083955
6
:
1409187084255
7
:
1409187084555
8
:
1409187084855
9
:
1409187085155
10
:
1409187085455
11
:
1409187085755
。。。
|
本文转自 leizhimin 51CTO博客,原文链接:http://blog.51cto.com/lavasoft/1545968,如需转载请自行联系原作者