Merge pull request #118 from vv-248430449/main

优化:线程全局异常处理器改为单例模式
This commit is contained in:
zongzibinbin
2023-08-19 15:38:39 +08:00
committed by GitHub
4 changed files with 11 additions and 3 deletions

View File

@@ -15,7 +15,7 @@ public class MyThreadFactory implements ThreadFactory {
@Override
public Thread newThread(Runnable r) {
Thread thread =factory.newThread(r);
thread.setUncaughtExceptionHandler(new GlobalUncaughtExceptionHandler());
thread.setUncaughtExceptionHandler(GlobalUncaughtExceptionHandler.getInstance());
return thread;
}
}

View File

@@ -5,10 +5,18 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class GlobalUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
private static final GlobalUncaughtExceptionHandler instance = new GlobalUncaughtExceptionHandler();
private GlobalUncaughtExceptionHandler() {
}
@Override
public void uncaughtException(Thread t, Throwable e) {
log.error("Exception in thread {} ", t.getName(), e);
}
public static GlobalUncaughtExceptionHandler getInstance() {
return instance;
}
}

View File

@@ -37,7 +37,7 @@ public class IpServiceImpl implements IpService, DisposableBean {
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(500),
new NamedThreadFactory("refresh-ipDetail", null, false,
new GlobalUncaughtExceptionHandler()));
GlobalUncaughtExceptionHandler.getInstance()));
@Autowired
private UserDao userDao;

View File

@@ -31,7 +31,7 @@ public class WeChatMsgOperationServiceImpl implements WeChatMsgOperationService
TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(20),
new NamedThreadFactory("wechat-operation-thread", null, false,
new GlobalUncaughtExceptionHandler()));
GlobalUncaughtExceptionHandler.getInstance()));
// at消息的微信推送模板id
private final String atMsgPublishTemplateId = "Xd7sWPZsuWa0UmpvLaZPvaJVjNj1KjEa0zLOm5_Z7IU";