mirror of
https://github.com/corda/corda.git
synced 2024-12-30 17:57:02 +00:00
9bb3d6b972
git-subtree-dir: sgx-jvm/avian git-subtree-mainline:f978eab8d1
git-subtree-split:09e4fe60d0
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 { }
|
|
|
|
}
|