Skip to content

Commit 06e984d

Browse files
committed
update
1 parent ca2297f commit 06e984d

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

src/main/java/Advances/Annotation/test1.java renamed to src/main/java/Advances/Annotation/Test1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.junit.jupiter.api.BeforeAll;
77
import org.junit.jupiter.api.Test;
88

9-
public class test1 {
9+
public class Test1 {
1010
private static Object[] array;
1111
private static int total;
1212

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package threadDev;
2+
3+
4+
import java.io.Serializable;
5+
import java.util.concurrent.Callable;
6+
7+
public class Fibonacci<Long> implements Callable<java.lang.Long>, Serializable {
8+
int input = 0;
9+
10+
public Fibonacci() {
11+
}
12+
13+
public Fibonacci(int input) {
14+
this.input = input;
15+
}
16+
17+
public java.lang.Long call() {
18+
return calculate (input);
19+
}
20+
21+
private long calculate (int n) {
22+
if (Thread.currentThread().isInterrupted()) return 0;
23+
if (n <= 1) return n;
24+
else return calculate(n-1) + calculate(n-2);
25+
}
26+
}

src/main/java/threadDev/Test1.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package threadDev;
2+
3+
// https://docs.hazelcast.org/docs/1.9/manual/html/ch07s02.html
4+
5+
import java.io.Serializable;
6+
import java.util.concurrent.*;
7+
8+
public class Test1 {
9+
public static void main(String[] args){
10+
11+
//ThreadPoolExecutor es = new ThreadPoolExecutor(10); //Hazelcast.getExecutorService();
12+
13+
final int _pcautoSchedulerPoolSize = 1000;
14+
final int KEEP_ALIVE_TIME = 60;
15+
16+
final int MAX_POOL_SIZE = 1000;
17+
final int CORE_POOL_SIZE = 500; // Example value, set according to your needs
18+
19+
ThreadPoolExecutor executor = new ThreadPoolExecutor(
20+
CORE_POOL_SIZE,
21+
MAX_POOL_SIZE,
22+
KEEP_ALIVE_TIME,
23+
TimeUnit.SECONDS,
24+
new SynchronousQueue<>(),
25+
new ThreadPoolExecutor.AbortPolicy() // DiscardPolicy
26+
);
27+
28+
Test1 t1 = new Test1();
29+
Fibonacci fibonacci = new Fibonacci();
30+
int n = 10;
31+
Future future = executor.submit(new Fibonacci(n));
32+
33+
try {
34+
//return future.get(3, TimeUnit.SECONDS);
35+
future.get(3, TimeUnit.SECONDS);
36+
} catch (TimeoutException e) {
37+
future.cancel(true);
38+
} catch (ExecutionException e) {
39+
throw new RuntimeException(e);
40+
} catch (InterruptedException e) {
41+
throw new RuntimeException(e);
42+
}
43+
44+
System.out.println(123);
45+
46+
}
47+
48+
public void myFunc(){
49+
System.out.println(123);
50+
}
51+
52+
53+
}

0 commit comments

Comments
 (0)