在有些严格的系统中,我们需要做到干净的停止线程并清理相关状态.涉及到这个主题会带出很多的相关点,简单的总结如下: 我们知道,在java中,有一个volatile关键字,其官方说明(https://docs.oracle.com/javase/tutorial/essential/concurrency/atomic.html)为: Using volatile variables reduces the risk of memory consistency errors, because any
最近在高并发的系统中发现,concurrenthashmap除了大家熟知的避免循环期间发生ConcurrentModificationException异常外,还有重要的一点是Retrievals reflect the results of the most recently completed update operations holding upon their onset,也就是get的时候会得到最新后的结果,线程间亦如此.而hashmap并没有提及一点,所以并不能保证另一个线程在之后