创建线程池
private ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat(channel + "-pool-%d").build();
/**
* 线程池
*/
private ExecutorService pool = new ThreadPoolExecutor(5,
200,
0L,
TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(1024),
namedThreadFactory,
new ThreadPoolExecutor.AbortPolicy());
pool.execute(() -> {
while (true) {
try {
// 初始化环境
LocalMessage message = LocalMessageQueue.out(channel);
pool.execute(() -> consumer(message));
}
catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
if (false) {
break;
}
}
});