首页 > 为什么这段代码在jdk12中没有引发死锁呢?
头像
牛客196669835号
编辑于 2021-04-21 17:48
+ 关注

为什么这段代码在jdk12中没有引发死锁呢?

包com;
公共类DeadLockDemo {    私有静态字符串A =“ A”;    私有静态字符串B =“ B”;    公共静态void main(String [] args)抛出InterruptedException {        新的DeadLockDemo()。deadLock();    }    私人无效deadLock(){        线程t1 =新线程(新Runnable(){@Overridepublic void run(){                已同步(A){                    尝试 {                        Thread.currentThread()。sleep(2000);                    } catch(InterruptedException e){                        e.printStackTrace();                    }                }                已同步(B){                    System.out.println(“ 1”);                }            }        });        线程t2 =新线程(新Runnable(){@Overridepublic void run(){                已同步(B){                    已同步(A){                        System.out.println(“ 2”);                    }                }            }        });        t1.start();        t2.start();    }}


全部评论

(1) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

近期精华帖

热门推荐