File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments