蘇阿細
首页 统计 关于
1 Sealos3.0离线部署K8s集群 1,082 阅读 2 类的加载 741 阅读 3 Spring Cloud OAuth2.0 726 阅读 4 SpringBoot自动装配原理 691 阅读 5 集合不安全问题 584 阅读
笔记
Java
多线程 注解和反射 JVM JUC 设计模式 Mybatis Spring SpringMVC SpringBoot MyBatis-Plus Elastic Search
微服务
Dubbo Zookeeper SpringCloud Nacos Sentinel
数据库
MySQL Oracle PostgreSQL Redis MongoDB
工作流
Activiti7 Camunda
消息队列
RabbitMQ
前端
HTML5 CSS CSS3 JavaScript jQuery Vue2 Vue3
Linux
容器
Docker Kubernetes
Python
登录
标签搜索
  • Java
  • CSS
  • mysql
  • RabbitMQ
  • JavaScript
  • Redis
  • JVM
  • Mybatis-Plus
  • Camunda
  • 多线程
  • CSS3
  • Python
  • Spring Cloud
  • 注解和反射
  • Activiti
  • 工作流
  • SpringBoot
  • Mybatis
  • Spring
  • html5
侧边栏壁纸
博主昵称
蘇阿細

  • 累计撰写 388 篇文章
  • 累计收到 4 条评论
  • 首页
  • 栏目
    • 笔记
    • Java
      • 多线程
      • 注解和反射
      • JVM
      • JUC
      • 设计模式
      • Mybatis
      • Spring
      • SpringMVC
      • SpringBoot
      • MyBatis-Plus
      • Elastic Search
    • 微服务
      • Dubbo
      • Zookeeper
      • SpringCloud
      • Nacos
      • Sentinel
    • 数据库
      • MySQL
      • Oracle
      • PostgreSQL
      • Redis
      • MongoDB
    • 工作流
      • Activiti7
      • Camunda
    • 消息队列
      • RabbitMQ
    • 前端
      • HTML5
      • CSS
      • CSS3
      • JavaScript
      • jQuery
      • Vue2
      • Vue3
    • Linux
    • 容器
      • Docker
      • Kubernetes
    • Python
  • 页面
    • 统计
    • 关于
搜索到 1 篇与 的结果
  • 自旋锁 2021-02-23
    自旋锁 自旋锁spinlock自定义自旋锁测试实例package com.sw.lock; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; /** * @Author suaxi * @Date 2021/2/22 23:21 * 自定义自旋锁 */ public class SpinLockTest { AtomicReference<Thread> atomicReference = new AtomicReference<>(); //加锁 public void myLock() { Thread thread = Thread.currentThread(); System.out.println(Thread.currentThread().getName() + "--->myLock()"); //自旋锁 while (!atomicReference.compareAndSet(null, thread)) { } } //解锁 public void myUnlock() { Thread thread = Thread.currentThread(); System.out.println(Thread.currentThread().getName() + "--->myUnlock()"); atomicReference.compareAndSet(thread, null); } //测试 public static void main(String[] args) throws InterruptedException { SpinLockTest lock = new SpinLockTest(); new Thread(() -> { lock.myLock(); try { TimeUnit.SECONDS.sleep(5); } catch (InterruptedException e) { e.printStackTrace(); } finally { lock.myUnlock(); } }, "A").start(); TimeUnit.SECONDS.sleep(2); new Thread(() -> { lock.myLock(); try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { e.printStackTrace(); } finally { lock.myUnlock(); } }, "B").start(); /* 执行结果为: A--->myLock() B--->myLock() A--->myUnlock() B--->myUnlock() */ } }
    • 2021年02月23日
    • 55 阅读
    • 0 评论
    • 0 点赞
博主栏壁纸
博主头像 蘇阿細

388 文章数
4 评论量
标签
舔狗日记
2019 - 2025 © suaxi
已运行 00 天
访问量:310764  加载时间:15ms