|
|
@@ -37,12 +37,9 @@ public class ThreadUtils {
|
|
|
}
|
|
|
|
|
|
public static Executor task(Runnable runnable) {
|
|
|
- return new Executor().task(runnable);
|
|
|
+ return Executor.getExecutor().task(runnable);
|
|
|
}
|
|
|
|
|
|
- public static Executor pool(int poolSize) {
|
|
|
- return new Executor(poolSize);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* @param <T>
|
|
|
@@ -212,13 +209,21 @@ public class ThreadUtils {
|
|
|
private final ExecutorService threadPool;
|
|
|
private int timeout = 900;// 15 min
|
|
|
private int taskCount = 0;
|
|
|
+ private static Executor executor = null;
|
|
|
|
|
|
- public Executor() {
|
|
|
- this.threadPool = Executors.newCachedThreadPool();
|
|
|
+ public static Executor getExecutor() {
|
|
|
+ if (executor == null) {
|
|
|
+ synchronized (Executor.class) {
|
|
|
+ if (executor == null) {
|
|
|
+ executor = new Executor();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return executor;
|
|
|
}
|
|
|
|
|
|
- public Executor(int poolSize) {
|
|
|
- this.threadPool = Executors.newFixedThreadPool(poolSize);
|
|
|
+ private Executor() {
|
|
|
+ this.threadPool = Executors.newFixedThreadPool(1000);
|
|
|
}
|
|
|
|
|
|
public Executor setTimeout(int timeout) {
|