Explorar el Código

增加线程安全处理

master
林万龙 hace 3 años
padre
commit
4dbcc2cff4
Se han modificado 1 ficheros con 5 adiciones y 4 borrados
  1. +5
    -4
      src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java

+ 5
- 4
src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java Ver fichero

@@ -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);
//}


Cargando…
Cancelar
Guardar