GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 更新 docs/10.并发多线程/02.我跟老婆讲CAS原理,被鄙视太简单!15张图 -源码调试 .md · owen2016/PassJava-Learning@9b3a29a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • code/01.Threads/src/com/jackson0714/passjava/threads
    • CASDemo.java
  • docs/10.并发多线程
    • 01.反制面试官_14张原理图_再也不怕被问volatile!.md
    • 02.我跟老婆讲CAS原理,被鄙视太简单!15张图 -源码调试 .md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎code/01.Threads/src/com/jackson0714/passjava/threads/CASDemo.java‎

Copy file name to clipboardExpand all lines: code/01.Threads/src/com/jackson0714/passjava/threads/CASDemo.java
+13-5Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@
66
* @create: 2020-08-17
77
*/
88
public class CASDemo {
9-
public static void main(String[] args) {
9+
public static void main(String[] args) throws InterruptedException {
1010
AtomicInteger atomicInteger = new AtomicInteger(10);
11-
Boolean result1 = atomicInteger.compareAndSet(10,20);
12-
System.out.printf("当前atomicInteger变量的值:%d 比较结果%s\r\n", atomicInteger.get(), result1);
13-
Boolean result2 = atomicInteger.compareAndSet(10,30);
14-
System.out.printf("当前atomicInteger变量的值:%d, 比较结果%s\n" , atomicInteger.get(), result2);
11+
Thread.sleep(100);
12+
13+
new Thread(() -> {
14+
atomicInteger.getAndIncrement();
15+
}, "aaa").start();
16+
17+
atomicInteger.getAndIncrement();
18+
}
19+
20+
private static void demo() {
21+
AtomicInteger atomicInteger = new AtomicInteger(10);
22+
atomicInteger.getAndIncrement();
1523
}
1624
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.