Bounded executor
@@ -74,6 +74,12 @@ public class Threads{
return unboundedExecutor(null);
}
+ /** @return an executor with a max thread count. threads expire after 1 minute of inactivity
+ * @param max maximum number of threads to create */
+ public static ExecutorService boundedExecutor(@Nullable String name, int max){
+ return new ThreadPoolExecutor(1, max, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<>(), r -> newThread(r, name, true));
+ }
+
/** Shuts down the executor and waits for its termination indefinitely. */
public static void await(ExecutorService exec){
try{
