Browse Source

Merge remote-tracking branch 'origin/dev' into dev

dongbw 7 years ago
parent
commit
e6ebbd5e21
1 changed files with 13 additions and 8 deletions
  1. 13 8
      src/main/java/com/uas/ps/inquiry/util/ThreadUtils.java

+ 13 - 8
src/main/java/com/uas/ps/inquiry/util/ThreadUtils.java

@@ -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) {