测试目的
据我的了解, 在高并发环境下, 为了减少锁的开销(睡眠, 线程上下文切换), 采用的是无锁编程(lock-free or lockless programming), 而无锁编程的基础是CAS操作, 那么CAS操作在高并发下的效果怎样, 怎么尽量避免并发带来的问题.
测试的Java代码:
package com.lqp.test;
import java.util.concurrent.atomic.AtomicLong;
public class ConcurrentCASTest {
public static void main(String[] args) throws Exception {
final AtomicLong value = new AtomicLong();
final int count = 100 * 10000;
int threadCount = 1;
for (int i = 0; i < threadCount; i++) {
final int id = i;
new Th