Java 类加载出现死锁? 转
出处: Java 类加载还会死锁?这是什么情况? 一、前言 先贴一份测试代码,大家可以先猜测一下,执行结果会是怎样的: import java.util.concurrent.TimeUnit; public class TestClassLoading { public static class A{ static { System.out.println( "class A init" ); try { TimeUnit.SECONDS.sleep( 1 ); } catch (InterruptedException e) { e.printStackTrace(); } new B(); } public static void test() { System.out.println( "aaa" ); } } public static class B{ static { System.out.println( "class B init" ); new A(); } public static void test() { System.out.println( "bbb" ); } } public static void main(String[] args) { new Thread(() -> A.test()).start(); new Thread(() ->