Commit 60dd03cb authored by tangwei's avatar tangwei

测试

parent 749ff636
...@@ -166,7 +166,7 @@ public class EquipmentIotMqttReceiveConfig { ...@@ -166,7 +166,7 @@ public class EquipmentIotMqttReceiveConfig {
//mqttReceiveService.handlerMqttIncrementMessage(topic, msg); //mqttReceiveService.handlerMqttIncrementMessage(topic, msg);
//异步处理 //异步处理
EquipmentIotMqttReceiveConfig controllerProxy = SpringUtils.getBean(EquipmentIotMqttReceiveConfig.class); EquipmentIotMqttReceiveConfig controllerProxy = SpringUtils.getBean(EquipmentIotMqttReceiveConfig.class);
controllerProxy.handlerMqttIncrementMessage(topic, msg); controllerProxy.namePrefixhandlerMqttIncrementMessage(topic, msg);
} else if (dataType.equals("event") && StringUtil.isNotEmpty(msg)) { } else if (dataType.equals("event") && StringUtil.isNotEmpty(msg)) {
...@@ -184,7 +184,7 @@ public class EquipmentIotMqttReceiveConfig { ...@@ -184,7 +184,7 @@ public class EquipmentIotMqttReceiveConfig {
@Async("equipAsyncExecutor") @Async("equipAsyncExecutor")
public void handlerMqttIncrementMessage(String topic, String msg) { public void namePrefixhandlerMqttIncrementMessage(String topic, String msg) {
if(cluster.equals("cluster")){ if(cluster.equals("cluster")){
//不同设备加锁,防止消息顺序错乱,此处加锁高并发下小概率会出现顺序错乱, //不同设备加锁,防止消息顺序错乱,此处加锁高并发下小概率会出现顺序错乱,
...@@ -192,9 +192,18 @@ public class EquipmentIotMqttReceiveConfig { ...@@ -192,9 +192,18 @@ public class EquipmentIotMqttReceiveConfig {
RLock lock = redisson.getLock(topic); RLock lock = redisson.getLock(topic);
try { try {
//拿锁失败10停止尝试,20秒后直接释放锁 无论是返回 true 还是 false,都会继续执行之后的代码。 //拿锁失败10停止尝试,20秒后直接释放锁 无论是返回 true 还是 false,都会继续执行之后的代码。
lock.tryLock(10, 20, TimeUnit.SECONDS); boolean flag= lock.tryLock(2, 20, TimeUnit.SECONDS);
System.out.println("msg==================================="+flag);
for (int i = 0; i <= 1000000; i++)
{
System.out.println("msg==================================="+i);
}
//为了防止重复 //为了防止重复
mqttReceiveService.handlerMqttIncrementMessage(topic, msg); mqttReceiveService.handlerMqttIncrementMessage(topic, msg);
System.out.println("msg==================================="+msg);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment