Skip to content

Commit 94b28c6

Browse files
committed
update
1 parent 06e984d commit 94b28c6

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

src/main/java/threadDev/Fibonacci.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public Fibonacci() {
1111
}
1212

1313
public Fibonacci(int input) {
14+
System.out.println("Fibonacci init ..., input = " + input);
1415
this.input = input;
1516
}
1617

src/main/java/threadDev/Test1.java

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public static void main(String[] args){
1010

1111
//ThreadPoolExecutor es = new ThreadPoolExecutor(10); //Hazelcast.getExecutorService();
1212

13-
final int _pcautoSchedulerPoolSize = 1000;
13+
final int _pcautoSchedulerPoolSize = 10;
1414
final int KEEP_ALIVE_TIME = 60;
1515

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
1818

1919
ThreadPoolExecutor executor = new ThreadPoolExecutor(
2020
CORE_POOL_SIZE,
@@ -25,20 +25,56 @@ public static void main(String[] args){
2525
new ThreadPoolExecutor.AbortPolicy() // DiscardPolicy
2626
);
2727

28-
Test1 t1 = new Test1();
28+
//Test1 t1 = new Test1();
2929
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+
3355
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+
3465
//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));
3668
} catch (TimeoutException e) {
69+
System.out.println("future cancel");
3770
future.cancel(true);
3871
} catch (ExecutionException e) {
3972
throw new RuntimeException(e);
4073
} catch (InterruptedException e) {
4174
throw new RuntimeException(e);
75+
}finally{
76+
System.out.println("executor shutdown");
77+
executor.shutdown();
4278
}
4379

4480
System.out.println(123);

0 commit comments

Comments
 (0)