Skip to content

Commit 3692af7

Browse files
committed
getMaximunPoolSize, allowsCoreThreadTimeOut
1 parent 258ba7e commit 3692af7

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import java.util.concurrent.*;
2+
3+
class MyThread implements Runnable {
4+
5+
int num;
6+
MyThread(int num) {
7+
8+
this.num = num;
9+
}
10+
11+
public void run() {
12+
13+
System.out.println(Thread.currentThread() + " Start : " + num);
14+
dailyTask();
15+
System.out.println(Thread.currentThread() + " End : " + num);
16+
}
17+
void dailyTask() {
18+
19+
try {
20+
21+
Thread.sleep(1000);
22+
} catch(InterruptedException ie) {
23+
24+
25+
}
26+
}
27+
}
28+
29+
class Main {
30+
31+
public static void main(String[] args) {
32+
33+
ThreadPoolExecutor tes = (ThreadPoolExecutor)Executors.newFixedThreadPool(10);
34+
35+
for(int i = 1; i < 5; i++) {
36+
37+
MyThread obj = new MyThread(i);
38+
tes.execute(obj);
39+
}
40+
System.out.println(tes.getMaximumPoolSize());
41+
System.out.println(tes.allowsCoreThreadTimeOut());
42+
System.out.println(tes.getMaximumPoolSize());
43+
tes.shutdown();
44+
}
45+
}

0 commit comments

Comments
 (0)