forked from Somersames/JavaBasis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExectest.java
More file actions
40 lines (37 loc) · 957 Bytes
/
Exectest.java
File metadata and controls
40 lines (37 loc) · 957 Bytes
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
28
29
30
31
32
33
34
35
36
37
38
39
40
package Thread.test;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Created by szh on 2017/5/9.
*/
public class Exectest {
public static void main(String args[]) throws InterruptedException {
int i=0;
for(i=0; i<10 ; i++){
Thread.currentThread().sleep(200);
}
while (i>=9){
new RunExec().sp();
}
}
}
class RunExec {
ExecutorService executor = Executors.newFixedThreadPool(5);
static int num = 0;
public void sp() {
if(num >1000)
executor.shutdown();
executor.execute(new Runnable() {
@Override
public void run() {
System.out.println(num);
num++;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
}
}