原子值:主要用于缓存中唯一的要求,比如队伍,要分配一个 id,并且该id不保存数据库.每次重启服务器,都从指定的值开始.
尝试使用了AtomicInteger这个类,感觉使用起来很爽,特别适用于高并发访问
public static AtomicInteger teamID = new AtomicInteger();
Integer tID = teamID.incrementAndGet(); 获取下一个id
尝试使用了AtomicInteger这个类,感觉使用起来很爽,特别适用于高并发访问
public static AtomicInteger teamID = new AtomicInteger();
Integer tID = teamID.incrementAndGet(); 获取下一个id
本文介绍如何利用AtomicInteger类生成缓存中的唯一ID,如团队标识等,并探讨其在高并发场景下的应用。
693

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



