摘要:
private static final ThreadLocal<Integer> THREAD_LOCAL = new ThreadLocal<>(); @Test void threadLocalTest() { Assertions.assertDoesNotThrow(() -> { // 阅读全文
摘要:
Reentrantlock默认是非公平锁 private static ReentrantLock lock = new ReentrantLock(); 若想实现公平锁,只需使用重载构造器,fair参数传入true private static ReentrantLock lock = new R 阅读全文
摘要:
synchronized 关键字用于实现对象级别的同步,它可以保证多个线程在访问某个对象时的互斥性,避免并发访问导致的数据竞争和不一致 public class BankAccount { private BigDecimal balance; public BankAccount(String i 阅读全文