Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Jul 11, 2024
1 parent 06e984d commit 94b28c6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/main/java/threadDev/Fibonacci.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public Fibonacci() {
}

public Fibonacci(int input) {
System.out.println("Fibonacci init ..., input = " + input);
this.input = input;
}

Expand Down
52 changes: 44 additions & 8 deletions src/main/java/threadDev/Test1.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public static void main(String[] args){

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

final int _pcautoSchedulerPoolSize = 1000;
final int _pcautoSchedulerPoolSize = 10;
final int KEEP_ALIVE_TIME = 60;

final int MAX_POOL_SIZE = 1000;
final int CORE_POOL_SIZE = 500; // Example value, set according to your needs
final int MAX_POOL_SIZE = 11;
final int CORE_POOL_SIZE = 10; // Example value, set according to your needs

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

Test1 t1 = new Test1();
//Test1 t1 = new Test1();
Fibonacci fibonacci = new Fibonacci();
int n = 10;
Future future = executor.submit(new Fibonacci(n));

System.out.println("executor submit task");

int N = 3;
Future future = executor.submit(() -> {
System.out.println("--> Thread name : " + Thread.currentThread().getName() + ", id = " + Thread.currentThread().getId());
//fibonacci.call(10);
new Fibonacci(N);
});

Fibonacci f = new Fibonacci(10);

// FutureTask<Integer> futureTask = new FutureTask<>(() -> {
// System.out.println("--> Thread name : " + Thread.currentThread().getName() + ", id = " + Thread.currentThread().getId());
// // Simulate some work, e.g., Fibonacci calculation
// //new Fibonacci(10); // Replace '10' with 'N' if 'N' is defined elsewhere
// });

for (int i = 0; i < 3; i++){
executor.submit(() -> {
System.out.println("--> Thread name : " + Thread.currentThread().getName() + ", id = " + Thread.currentThread().getId());
new Fibonacci(2);
});
}


try {

// while(!futureTask.isDone()){
// System.out.println("wait for futureTask done, sleep 3 milli sec");
// Thread.sleep(3);
// }
//
// System.out.println("futureTask.isDone() = " + futureTask.isDone());
// System.out.println("futureTask result = " + futureTask.get());

//return future.get(3, TimeUnit.SECONDS);
future.get(3, TimeUnit.SECONDS);
System.out.println("future.isDone() = " + future.isDone());
System.out.println("future result = " + future.get(10, TimeUnit.SECONDS));
} catch (TimeoutException e) {
System.out.println("future cancel");
future.cancel(true);
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}finally{
System.out.println("executor shutdown");
executor.shutdown();
}

System.out.println(123);
Expand Down

0 comments on commit 94b28c6

Please sign in to comment.