关于java:线程校验中断刷新

41次阅读

共计 698 个字符,预计需要花费 2 分钟才能阅读完成。

校验以后线程是否中断否则进行刷新

refreshThead = new Thread(() -> {logger.info("RMQ 对应接口消费者状态刷新...");
            while (!Thread.currentThread().isInterrupted()) {
                try {
                    try {Thread.sleep(1000 * QContext.RMQ_CONSUMER_REFRESH_INTERVAL);
                    } catch (InterruptedException ex) { }
                    if (logger.isDebugEnabled()) {logger.debug("执行 RMQ 对应接口消费者状态刷新......");
                    }
                    EsbCacheManager cacheManager = BeanFactoryHelper.getBean("esbCacheManager", EsbCacheManager.class);
                    QContext.rmqConsumerActionIds.forEach((k, v) -> cacheManager.recordActionIdForConsumerOk(v, QContext.RMQ_CONSUMER_TTL));
                } catch (Exception e) {logger.error("RMQ 对应接口消费者状态刷新出错", e);
                    try {Thread.sleep(10000);
                    } catch (InterruptedException ex) {}}
            }
        });

校验线程是否中断 Thread.currentThread() 返回以后线程对象,isInterrupted() 校验以后对象是否中断,不中断循环 while 内容一直得刷新

正文完
 0