• 大小: 4.06M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-06-23
  • 语言: Java
  • 标签: 代码  实例  

资源简介

关于JUC代码的一些小实例
这写代码实例是看B站的视频写的一些,主要是讲解的JUC部分
在resources目录下有markdown笔记以及生成的pdf文件
笔记里也有一些代码,但不是所有的代码都写了执行结果,大家可以自行去执行试试
markdown中有一些mermaid语法,如果不能显示的同学可以下载一个支持mermaid语法的工具,在下用的是Typora
如果不需要在原来基础上修改的同学直接看pdf就可以了

资源截图

代码片段和文件信息

package com.jian8.juc.cas;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicStampedReference;

/**
 * ABA问题解决
 * AtomicStampedReference
 */
public class ABADemo {
    static AtomicReference atomicReference = new AtomicReference<>(100);
    static AtomicStampedReference atomicStampedReference = new AtomicStampedReference<>(100 1);

    public static void main(String[] args) {
        System.out.println(“=====以下时ABA问题的产生=====“);
        new Thread(() -> {
            atomicReference.compareAndSet(100 101);
            atomicReference.compareAndSet(101 100);
        } “Thread 1“).start();

        new Thread(() -> {
            try {
                //保证线程1完成一次ABA操作
                TimeUni

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-06-02 14:18  ThreadDemo-master\
     文件          66  2019-06-02 14:18  ThreadDemo-master\.gitattributes
     文件          16  2019-06-02 14:18  ThreadDemo-master\.gitignore
     文件         532  2019-06-02 14:18  ThreadDemo-master\README.md
     文件        1308  2019-06-02 14:18  ThreadDemo-master\pom.xml
     目录           0  2019-06-02 14:18  ThreadDemo-master\src\
     目录           0  2019-06-02 14:18  ThreadDemo-master\src\main\
     目录           0  2019-06-02 14:18  ThreadDemo-master\src\main\java\
     目录           0  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\
     目录           0  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\
     目录           0  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\
     目录           0  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\cas\
     文件        2990  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\cas\ABADemo.java
     文件         744  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\cas\AtomicRefrenceDemo.java
     文件         551  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\cas\CASDemo.java
     目录           0  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\collection\
     文件        1979  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\collection\ContainerNotSafeDemo.java
     文件        1356  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\collection\HashSetTest.java
     文件         768  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\collection\MapSafe.java
     目录           0  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\conditionThread\
     文件        1338  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\conditionThread\CountDownLatchDemo.java
     文件         730  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\conditionThread\CountryEnum.java
     文件         968  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\conditionThread\CyclicBarrierDemo.java
     文件        1053  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\conditionThread\SemaphoreDemo.java
     目录           0  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\lock\
     文件        2703  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\lock\ReadWriteLockDemo.java
     文件         877  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\lock\ReentrantLockDemo.java
     文件        1682  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\lock\SpinLockDemo.java
     文件        2919  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\lock\SyncAndReentrantLockDemo.java
     文件         916  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\lock\SynchronizedDemo.java
     目录           0  2019-06-02 14:18  ThreadDemo-master\src\main\java\com\jian8\juc\queue\
............此处省略31个文件信息

评论

共有 条评论