mirror of
https://github.com/corda/corda.git
synced 2025-01-28 15:14:48 +00:00
9bb3d6b972
git-subtree-dir: sgx-jvm/avian git-subtree-mainline: f978eab8d134c88f88ff67e49458a771c32351db git-subtree-split: 09e4fe60d01f4f4bfb6b2976973bb4913ef61edc
45 lines
785 B
Java
45 lines
785 B
Java
public class Finalizers {
|
|
private static final Object lock = new Object();
|
|
private static boolean finalized = false;
|
|
|
|
private static void expect(boolean v) {
|
|
if (! v) throw new RuntimeException();
|
|
}
|
|
|
|
protected void finalize() {
|
|
synchronized (lock) {
|
|
finalized = true;
|
|
lock.notifyAll();
|
|
}
|
|
}
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
new Finalizers();
|
|
|
|
expect(! finalized);
|
|
|
|
synchronized (lock) {
|
|
System.gc();
|
|
lock.wait(5000);
|
|
}
|
|
|
|
expect(finalized);
|
|
|
|
new Finalizers2();
|
|
|
|
finalized = false;
|
|
|
|
expect(! finalized);
|
|
|
|
synchronized (lock) {
|
|
System.gc();
|
|
lock.wait(5000);
|
|
}
|
|
|
|
expect(finalized);
|
|
}
|
|
|
|
private static class Finalizers2 extends Finalizers { }
|
|
|
|
}
|