惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

博客园 - Ready!

Next.js 开发指南 路由篇 | 动态路由、路由组、平行路由和拦截路由 Next.js 开发指南 路由篇 | App Router Next.js 开发指南 初始篇 | Next.js CLI 设计百万日活用户手游实时排行榜 windows下,chmod 444 .. 的等价操作:操作文件的【安全】属性,保留当前用户的读取和执行权限。 HBase Storage Layout 3,turicreate入门 - 优化回归模型,使得预测更准确 2,turicreate入门 - 一个简单的回归模型 flink 配置 maven打包,带依赖jar python缓存所在目录 docker基础 yum安装 python3 flink 安装 BDAS - Berkeley Data Analytics Stack 分布式存储与传统数据库存储 nginx配置 - 反向代理,转发配置 解决nested exception is java.lang.NoClassDefFoundError: 问题的思路 JetBrains系列破解方法(以idea为主)
模拟死锁
Ready! · 2021-12-18 · via 博客园 - Ready!

模拟死锁

public class MyClass {
    private static Object resourceA = new Object();
    private static Object resourceB = new Object();
    
    public static void main(String args[]) {
      Thread threadA = new Thread( new Runnable() {
          public void run() {
              System.out.println(Thread.currentThread() + " getting A");
              synchronized (resourceA) {
                  System.out.println(Thread.currentThread() + " got A");
                  try {
                      Thread.sleep(1000);
                  } catch(InterruptedException e) {
                      e.printStackTrace();
                  }
                  
                  
                  System.out.println(Thread.currentThread() + " getting B");
                  synchronized (resourceB) {
                      System.out.println(Thread.currentThread() + " got B");
                      try {
                          Thread.sleep(1000);
                      } catch(InterruptedException e) {
                          e.printStackTrace();
                      }
                      
                  }
                  
              }
              
              
          }
      } );
      
      Thread threadB = new Thread( new Runnable() {
          public void run() {
              
              System.out.println(Thread.currentThread() + " getting B");
              synchronized (resourceB) {
                  System.out.println(Thread.currentThread() + " got B");
                  try {
                      Thread.sleep(1000);
                  } catch(InterruptedException e) {
                      e.printStackTrace();
                  }
                  
                  
                  System.out.println(Thread.currentThread() + " getting A");
                  synchronized (resourceA) {
                      System.out.println(Thread.currentThread() + " got A");
                      try {
                          Thread.sleep(1000);
                      } catch(InterruptedException e) {
                          e.printStackTrace();
                      }
                      
                  }
                  
              }
              
              
              
              
          }
      } );
      
      
      threadA.start();
      threadB.start();
    }
}

posted @ 2021-12-18 17:44  Ready!  阅读(75)  评论()    收藏  举报