Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathThreadsMu.java
More file actions
Latest commit
32 lines (27 loc) · 1.01 KB
/
Copy pathThreadsMu.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
packagemu;
importcom.google.common.util.concurrent.ThreadFactoryBuilder;
importjava.util.concurrent.BlockingQueue;
importjava.util.concurrent.LinkedBlockingQueue;
importjava.util.concurrent.ThreadPoolExecutor;
importjava.util.concurrent.TimeUnit;
publicclassThreadsMu {
publicstaticvoidsleep (longduration, TimeUnittimeUnit) {
try {
Thread.sleep(timeUnit.toMillis(duration));
} catch (InterruptedExceptione) {
throwExceptionsMu.handleInterruptedException(e);
}
}
publicstaticThreadPoolExecutorcreateThreadPoolExecutor(intthreadPoolSize, intworkQueueSize, StringpoolName) {
BlockingQueue<Runnable> workQueue = newLinkedBlockingQueue<>(workQueueSize);
ThreadPoolExecutorthreadPoolExecutor = newThreadPoolExecutor(
threadPoolSize,
threadPoolSize,
1,
TimeUnit.MINUTES,
workQueue,
newThreadFactoryBuilder().setNameFormat(poolName + "-%d").build());
threadPoolExecutor.allowCoreThreadTimeOut(true);
returnthreadPoolExecutor;
}
}