belary
belary
sorry for the mistake version ,i'm using the o0Zz here goes the log, |I|00:00:29.663|7F3570F0| SYS-CON started 1.5.1+0-5b301fa (Build date: Feb 22 2025 15:33:33) - https://github.com/o0Zz/sys-con |I|00:00:29.669|7F3570F0| OS version: 19.0.1 |I|00:03:09.442|7F34E070|...
感谢,遇到了同样的问题
i want to optimize shenyu-loadbalancer
hhaha, my file name is "sendgrid.py" and this is the reason
> 线程安全的容器与同步代码块作用不同,举个例子,如果不使用同步代码块,上面的代码逻辑改成下面这种 > > ```java > private int getAlarmCount(String key) { > if (!alarmCountMap.containsKey(key)) { // 1 > alarmCountMap.put(key, new AtomicInteger(0)); // 2 > } > > return alarmCountMap.get(key).addAndGet(1); >...
感谢回复,后来我查了一下资料,发现concurrentHashMap在read的时候是非阻塞的,而put的时候是阻塞的。因此我写了如下demo不知道是不是有什么我没发现的问题,无论怎么样都没出现返回为1的情况, 因此AlaramWrapper这里的使用并发安全的容器,就无需再使用Sync同步代码块来控制流程的并发了? ```java import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; /** * @Author: belary * @Date: 2022/3/3 10:38 * @Version 1.0 */ class TestMe implements Runnable{ private ConcurrentHashMap alarmCountMap; private String key; private...
>  非常感谢。我理解这个同步代码块的作用就是保证消息计数的map,针对每个key,在初始化的时候只能一个线程进行初始化。防止在多个线程同时初始化,从而影响后续的消息计数(本来应该是10而现在由于未进行同步初始化的保护,而得到非预期的消息计数)。 感谢感谢