浏览代码

增加线程安全处理

master
林万龙 3 年前
父节点
当前提交
4dbcc2cff4
共有 1 个文件被更改,包括 5 次插入4 次删除
  1. +5
    -4
      src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java

+ 5
- 4
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);
//}


正在加载...
取消
保存