@@ -10,11 +10,11 @@ public static void main(String[] args){
10
10
11
11
//ThreadPoolExecutor es = new ThreadPoolExecutor(10); //Hazelcast.getExecutorService();
12
12
13
- final int _pcautoSchedulerPoolSize = 1000 ;
13
+ final int _pcautoSchedulerPoolSize = 10 ;
14
14
final int KEEP_ALIVE_TIME = 60 ;
15
15
16
- final int MAX_POOL_SIZE = 1000 ;
17
- final int CORE_POOL_SIZE = 500 ; // Example value, set according to your needs
16
+ final int MAX_POOL_SIZE = 11 ;
17
+ final int CORE_POOL_SIZE = 10 ; // Example value, set according to your needs
18
18
19
19
ThreadPoolExecutor executor = new ThreadPoolExecutor (
20
20
CORE_POOL_SIZE ,
@@ -25,20 +25,56 @@ public static void main(String[] args){
25
25
new ThreadPoolExecutor .AbortPolicy () // DiscardPolicy
26
26
);
27
27
28
- Test1 t1 = new Test1 ();
28
+ // Test1 t1 = new Test1();
29
29
Fibonacci fibonacci = new Fibonacci ();
30
- int n = 10 ;
31
- Future future = executor .submit (new Fibonacci (n ));
32
-
30
+ System .out .println ("executor submit task" );
31
+
32
+ int N = 3 ;
33
+ Future future = executor .submit (() -> {
34
+ System .out .println ("--> Thread name : " + Thread .currentThread ().getName () + ", id = " + Thread .currentThread ().getId ());
35
+ //fibonacci.call(10);
36
+ new Fibonacci (N );
37
+ });
38
+
39
+ Fibonacci f = new Fibonacci (10 );
40
+
41
+ // FutureTask<Integer> futureTask = new FutureTask<>(() -> {
42
+ // System.out.println("--> Thread name : " + Thread.currentThread().getName() + ", id = " + Thread.currentThread().getId());
43
+ // // Simulate some work, e.g., Fibonacci calculation
44
+ // //new Fibonacci(10); // Replace '10' with 'N' if 'N' is defined elsewhere
45
+ // });
46
+
47
+ for (int i = 0 ; i < 3 ; i ++){
48
+ executor .submit (() -> {
49
+ System .out .println ("--> Thread name : " + Thread .currentThread ().getName () + ", id = " + Thread .currentThread ().getId ());
50
+ new Fibonacci (2 );
51
+ });
52
+ }
53
+
54
+
33
55
try {
56
+
57
+ // while(!futureTask.isDone()){
58
+ // System.out.println("wait for futureTask done, sleep 3 milli sec");
59
+ // Thread.sleep(3);
60
+ // }
61
+ //
62
+ // System.out.println("futureTask.isDone() = " + futureTask.isDone());
63
+ // System.out.println("futureTask result = " + futureTask.get());
64
+
34
65
//return future.get(3, TimeUnit.SECONDS);
35
- future .get (3 , TimeUnit .SECONDS );
66
+ System .out .println ("future.isDone() = " + future .isDone ());
67
+ System .out .println ("future result = " + future .get (10 , TimeUnit .SECONDS ));
36
68
} catch (TimeoutException e ) {
69
+ System .out .println ("future cancel" );
37
70
future .cancel (true );
38
71
} catch (ExecutionException e ) {
39
72
throw new RuntimeException (e );
40
73
} catch (InterruptedException e ) {
41
74
throw new RuntimeException (e );
75
+ }finally {
76
+ System .out .println ("executor shutdown" );
77
+ executor .shutdown ();
42
78
}
43
79
44
80
System .out .println (123 );
0 commit comments