-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch the shared pool to a normal threadpool and limit max concurren…
…t threads also fix #29
- Loading branch information
Showing
1 changed file
with
24 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
package lain.lib; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ForkJoinPool; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public final class SharedPool | ||
{ | ||
public final class SharedPool { | ||
|
||
private static final ExecutorService thePool = Executors.newWorkStealingPool(ForkJoinPool.getCommonPoolParallelism() + 1); | ||
private static final ExecutorService thePool = new ThreadPoolExecutor( | ||
2, | ||
Math.min(Runtime.getRuntime().availableProcessors() * 4, Short.MAX_VALUE), | ||
60L, | ||
TimeUnit.SECONDS, | ||
new LinkedBlockingQueue<>(), | ||
SharedPool::newWorker); | ||
|
||
public static void execute(Runnable command) | ||
{ | ||
thePool.execute(command); | ||
private SharedPool() { | ||
throw new Error("NoInstance"); | ||
} | ||
|
||
private static Thread newWorker(Runnable target) { | ||
Thread thread = new Thread(target, "SharedPoolWorker"); | ||
if (!thread.isDaemon()) | ||
thread.setDaemon(true); | ||
if (thread.getPriority() != Thread.NORM_PRIORITY) | ||
thread.setPriority(Thread.NORM_PRIORITY); | ||
return thread; | ||
} | ||
|
||
private SharedPool() | ||
{ | ||
public static void execute(Runnable command) { | ||
thePool.execute(command); | ||
} | ||
|
||
} |