Java 线程池简单使用

发布时间 2023-06-12 14:14:26作者: 章齐斌
    private final ThreadPoolExecutor handleExecutor = new ThreadPoolExecutor(
            3, 5, 5000L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(),
            new ThreadFactoryBuilder().setNameFormat("MsgCenterHandle-%d").build());

  

        handleExecutor.execute(() -> {
            try {
                if (res > 0) {
                    // 添加未读数量
                    msgCenterService.addUnReadCount(msgTypeId, userIdList);
                }
            } catch (Exception e) {
                log.error("消息盒子: 消息入库异常. {}", e, e);
            }
        });