场景:
根据ID去执行任务,每个任务都是确定的,数据装入了MAP中。
先取key,再取value。
分析
Map的实现类有HashMap 和ConcurrentHashMap,区别是HashMap线程不安全,ConcurrentHashMap线程安全。
Map<Integer,Integer> map = new ConcurrentHashMap<>(35);
map.<
本文探讨了在并发执行任务场景中ConcurrentHashMap的应用,对比了它与HashMap的区别,并提出了使用ConcurrentHashMap来保证数据读取原子性的解决方案。
场景:
根据ID去执行任务,每个任务都是确定的,数据装入了MAP中。
先取key,再取value。
分析
Map的实现类有HashMap 和ConcurrentHashMap,区别是HashMap线程不安全,ConcurrentHashMap线程安全。
Map<Integer,Integer> map = new ConcurrentHashMap<>(35);
map.<
608
1579

被折叠的 条评论
为什么被折叠?