/
IOThreadPool.java
37 lines (28 loc) · 1008 Bytes
/
IOThreadPool.java
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
33
34
35
36
37
package com.aliyun.openservices.aliyun.log.producer.internals;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.concurrent.*;
public class IOThreadPool {
private static final String IO_THREAD_SUFFIX_FORMAT = "-io-thread-%d";
private final ExecutorService ioThreadPool;
public IOThreadPool(int ioThreadCount, String prefix) {
this.ioThreadPool =
Executors.newFixedThreadPool(
ioThreadCount,
new ThreadFactoryBuilder()
.setDaemon(true)
.setNameFormat(prefix + IO_THREAD_SUFFIX_FORMAT)
.build());
}
public void submit(SendProducerBatchTask task) {
ioThreadPool.submit(task);
}
public void shutdown() {
ioThreadPool.shutdown();
}
public boolean isTerminated() {
return ioThreadPool.isTerminated();
}
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
return ioThreadPool.awaitTermination(timeout, unit);
}
}