乐观锁和悲观锁
public synchronized void testMethod() {
//操作同步资源
}Private ReentrantLock lock = new ReentrantLock();
Public void modifyPublicResource() {
lock.lock();
//操作同步资源
lock.unlock();
}最后更新于
public synchronized void testMethod() {
//操作同步资源
}Private ReentrantLock lock = new ReentrantLock();
Public void modifyPublicResource() {
lock.lock();
//操作同步资源
lock.unlock();
}最后更新于
private AtomicInteger atomicInteger = new AtomicInteger();
AtomicInteger.incrementAndGet();