1.完善采集线程的未知异常捕获。2.设置采集线程名字 3.去除多余的日志打印

This commit is contained in:
zhouxiunai
2019-04-01 14:28:33 +08:00
parent ddb1b8f95e
commit 2fc33ec611
2 changed files with 23 additions and 20 deletions
@@ -2,11 +2,13 @@ package com.gzzn.omms.msgexchangeapi.service;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.gzzn.omms.msgexchangeapi.runner.MsgExchangeRunner;
@Service
@@ -25,7 +27,10 @@ public class MsgExchangeServiceImpl implements IMsgExchangeService {
{
//启动消息采集线程
if (null == scheduledExecutorService) {
scheduledExecutorService = Executors.newScheduledThreadPool(1);
ThreadFactory namedThreadFactory =
new ThreadFactoryBuilder().setNameFormat("msgexchange-%d").build(); //为线程池添加名字
scheduledExecutorService = Executors.newScheduledThreadPool(1, namedThreadFactory);
scheduledExecutorService.scheduleAtFixedRate(new MsgExchangeRunner(), 0, intervalSeconds , TimeUnit.SECONDS);
}
}