首先了解一些知识 锁 CAS机制(Unsafe类中的方法,全称为Compare and Swap):参数(V内存中的value,E预期值expect,N用来更新内存value的新值) volatile关键字 synchronized关键字 Reentrantlock 参考:文中超链接地址