This action will force synchronization from yutf99/JavaDemo, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
package thread;public class DeadLock{public static void main(String[] args){DeadLockThread d = new DeadLockThread();new Thread(d).start();d.init();}static class A{public synchronized void foo(B b){System.out.println(Thread.currentThread().getName() + "进入A类的foo()方法");try{Thread.sleep(500);System.out.println(Thread.currentThread().getName() + "企图调用b对象的last()方法");b.last();} catch (InterruptedException e){e.printStackTrace();}}public synchronized void last(){System.out.println(Thread.currentThread().getName() + "调用A类的last()方法");}}static class B{public synchronized void foo(A a){System.out.println(Thread.currentThread().getName() + "进入B类的foo()方法");try{Thread.sleep(500);System.out.println(Thread.currentThread().getName() + "企图调用a对象的last()方法");a.last();} catch (InterruptedException e){e.printStackTrace();}}public synchronized void last(){System.out.println(Thread.currentThread().getName() + "调用B类的last()方法");}}static class DeadLockThread implements Runnable{A a = new A();B b = new B();public void init(){Thread.currentThread().setName("主线程");a.foo(b);}@Overridepublic void run(){Thread.currentThread().setName("子线程");b.foo(a);}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。