There is outer class Actions and its static inner class Add. Actions creates instance of class Add in its static constructor:
private static final Add ADD = new Add ();
Inner class even if static keeps reference to outer class using $assertionsDisabled:Z
When class Actions and its inner class are loaded simultaneously by different thread it causes deadlock.
I will attach 2 thread dumps.
###@###.### 10/4/04 12:28 GMT
Here is a test case. Not able to reproduce it on single processor Linux machine but it happens always on 2 CPU machine with Solaris 9 both with JDK 1.4.2_05 and JDK 1.5.0. I attach new thread dumps for given test case. Test case consists of Main.java and MyOuter.java. Important: assert is necessary in inner class code to generate hidden link to outer class as mentioned above.
Main.java:
package javaapplication1;
public class Main {
public Main() {
}
public static void main(String[] args) {
Thread t1 = new Thread () {
public void run() {
System.out.println("Test thread 1 start th:" + Integer.toHexString(System.identityHashCode(this)));
try {
Class c = Class.forName("javaapplication1.MyOuter");
System.out.println("c:" + c);
} catch (ClassNotFoundException exc) {
System.out.println("exc:" + exc);
}
System.out.println("Test thread 1 end");
}
};
Thread t2 = new Thread () {
public void run() {
System.out.println("Test thread 2 start th:" + Integer.toHexString(System.identityHashCode(this)));
try {
Class c = Class.forName("javaapplication1.MyOuter$MyInner");
System.out.println("c:" + c);
} catch (ClassNotFoundException exc) {
System.out.println("exc:" + exc);
}
System.out.println("Test thread 2 end");
}
};
t1.start();
t2.start();
try {
t1.join();
t2.join();
} catch (InterruptedException exc) {
System.out.println("exc:" + exc);
}
}
}
MyOuter.java:
package javaapplication1;
public class MyOuter {
private static MyInner A = new MyInner();
public MyOuter () {
System.out.println("MyOuter constructor");
}
public static class MyInner {
public MyInner () {
System.out.println("MyInner constructor");
}
public void t () {
assert(getClass().getName().length() > 20);
}
}
}
###@###.### 10/11/04 12:16 GMT
private static final Add ADD = new Add ();
Inner class even if static keeps reference to outer class using $assertionsDisabled:Z
When class Actions and its inner class are loaded simultaneously by different thread it causes deadlock.
I will attach 2 thread dumps.
###@###.### 10/4/04 12:28 GMT
Here is a test case. Not able to reproduce it on single processor Linux machine but it happens always on 2 CPU machine with Solaris 9 both with JDK 1.4.2_05 and JDK 1.5.0. I attach new thread dumps for given test case. Test case consists of Main.java and MyOuter.java. Important: assert is necessary in inner class code to generate hidden link to outer class as mentioned above.
Main.java:
package javaapplication1;
public class Main {
public Main() {
}
public static void main(String[] args) {
Thread t1 = new Thread () {
public void run() {
System.out.println("Test thread 1 start th:" + Integer.toHexString(System.identityHashCode(this)));
try {
Class c = Class.forName("javaapplication1.MyOuter");
System.out.println("c:" + c);
} catch (ClassNotFoundException exc) {
System.out.println("exc:" + exc);
}
System.out.println("Test thread 1 end");
}
};
Thread t2 = new Thread () {
public void run() {
System.out.println("Test thread 2 start th:" + Integer.toHexString(System.identityHashCode(this)));
try {
Class c = Class.forName("javaapplication1.MyOuter$MyInner");
System.out.println("c:" + c);
} catch (ClassNotFoundException exc) {
System.out.println("exc:" + exc);
}
System.out.println("Test thread 2 end");
}
};
t1.start();
t2.start();
try {
t1.join();
t2.join();
} catch (InterruptedException exc) {
System.out.println("exc:" + exc);
}
}
}
MyOuter.java:
package javaapplication1;
public class MyOuter {
private static MyInner A = new MyInner();
public MyOuter () {
System.out.println("MyOuter constructor");
}
public static class MyInner {
public MyInner () {
System.out.println("MyInner constructor");
}
public void t () {
assert(getClass().getName().length() > 20);
}
}
}
###@###.### 10/11/04 12:16 GMT
- duplicates
-
JDK-4721826 can an assertion in a nested class cause the outermost class to be init'd?
-
- Resolved
-