欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

玩转Java并发工具精通JUC成为并发多面手【15章完整版】笔记

时间:2023-06-30

玩转Java并发工具精通JUC成为并发多面手【15章完整版】 笔记汇总 

对Java并发常见的工具类进行从使用到原理的详解,
包括CAS+AQS+ThreadLocal+ConcurrentHashMap+线程池+各种锁+并发综合实战项目

下载:链接:https://pan.baidu.com/s/1u6xXLnNUd7jBqw7dxoymeQ 
提取码:9voy 

package cas;import java.util.concurrent.ConcurrentHashMap;import java.util.concurrent.atomic.AtomicInteger;import java.util.concurrent.atomic.AtomicIntegerArray;public class TwoThreadsCompetition implements Runnable { private volatile int value; public synchronized int compareAndSwap(int expectedValue, int newValue) { int oldValue = value; if (oldValue == expectedValue) { value = newValue; } return oldValue; } public static void main(String[] args) throws InterruptedException { TwoThreadsCompetition r = new TwoThreadsCompetition(); r.value = 0; Thread t1 = new Thread(r,"Thread 1"); Thread t2 = new Thread(r,"Thread 2"); t1.start(); t2.start(); t1.join(); t2.join(); System.out.println(r.value); } @Override public void run() { compareAndSwap(0, 1); }}

下载:链接:https://pan.baidu.com/s/1u6xXLnNUd7jBqw7dxoymeQ 
提取码:9voy 

public class SimulatedCAS { private volatile int value; public synchronized int compareAndSwap(int expectedValue, int newValue) { int oldValue = value; if (oldValue == expectedValue) { value = newValue; } return oldValue; }}

 

 

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。