diff --git a/src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java b/src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java index 10633a7..c6825b3 100644 --- a/src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java +++ b/src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java @@ -8,6 +8,7 @@ import org.springframework.stereotype.Component; import javax.jms.Message; import javax.jms.MessageListener; import java.util.concurrent.ExecutorService; +import java.util.concurrent.atomic.AtomicInteger; /** * @program: iotgateway @@ -19,7 +20,7 @@ import java.util.concurrent.ExecutorService; @Component public class IotMessageListener implements MessageListener { - private int count = 0; + private AtomicInteger count = new AtomicInteger(0); private ExecutorService executorService; public void setExecutorService(ExecutorService executorService) { @@ -54,8 +55,8 @@ public class IotMessageListener implements MessageListener { + ", topic = " + topic + ", messageId = " + messageId + ", content = " + content); - count++; - log.info("count is : " + count); + count.getAndIncrement(); + log.info("count is : " + count.toString()); } catch (Exception e) { log.error("processMessage occurs error ", e); } @@ -67,7 +68,7 @@ public class IotMessageListener implements MessageListener { // 获取推送失败的记录 //try { log.warn("约1分钟处理 {} 个请求",count); - count = 0; + count.getAndSet(0); //} catch (Exception e) { // log.error("执行定时计数发生异常:", e); //}