-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathThreadsMu.java
More file actions
32 lines (27 loc) · 1.01 KB
/
ThreadsMu.java
File metadata and controls
32 lines (27 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package mu;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class ThreadsMu {
public static void sleep (long duration, TimeUnit timeUnit) {
try {
Thread.sleep(timeUnit.toMillis(duration));
} catch (InterruptedException e) {
throw ExceptionsMu.handleInterruptedException(e);
}
}
public static ThreadPoolExecutor createThreadPoolExecutor(int threadPoolSize, int workQueueSize, String poolName) {
BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(workQueueSize);
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
threadPoolSize,
threadPoolSize,
1,
TimeUnit.MINUTES,
workQueue,
new ThreadFactoryBuilder().setNameFormat(poolName + "-%d").build());
threadPoolExecutor.allowCoreThreadTimeOut(true);
return threadPoolExecutor;
}
}