corda/sgx-jvm/avian/test/Finalizers.java
Andras Slemmer 9bb3d6b972 Add 'sgx-jvm/avian/' from commit '09e4fe60d01f4f4bfb6b2976973bb4913ef61edc'
git-subtree-dir: sgx-jvm/avian
git-subtree-mainline: f978eab8d1
git-subtree-split: 09e4fe60d0
2017-03-13 12:18:24 +00:00

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 { }
}