This closes #217

This commit is contained in:
Clebert Suconic 2015-10-26 10:53:48 -04:00
commit 8c6ba443a3
1 changed files with 20 additions and 3 deletions

View File

@ -525,10 +525,12 @@ public abstract class ActiveMQTestBase extends Assert {
public static void forceGC() { public static void forceGC() {
log.info("#test forceGC"); log.info("#test forceGC");
WeakReference<Object> dumbReference = new WeakReference<Object>(new Object()); AtomicInteger finalized = new AtomicInteger(0);
WeakReference<DumbReference> dumbReference = new WeakReference<>(new DumbReference(finalized));
// A loop that will wait GC, using the minimal time as possible // A loop that will wait GC, using the minimal time as possible
while (dumbReference.get() != null) { while (!(dumbReference.get() == null && finalized.get() == 1)) {
System.gc(); System.gc();
System.runFinalization();
try { try {
Thread.sleep(100); Thread.sleep(100);
} }
@ -2535,4 +2537,19 @@ public abstract class ActiveMQTestBase extends Assert {
public static void waitForLatch(CountDownLatch latch) throws InterruptedException { public static void waitForLatch(CountDownLatch latch) throws InterruptedException {
assertTrue("Latch has got to return within a minute", latch.await(1, TimeUnit.MINUTES)); assertTrue("Latch has got to return within a minute", latch.await(1, TimeUnit.MINUTES));
} }
}
protected static class DumbReference {
private AtomicInteger finalized;
public DumbReference(AtomicInteger finalized) {
this.finalized = finalized;
}
public void finalize() throws Throwable {
System.out.println("FINALIZE");
finalized.incrementAndGet();
super.finalize();
}
}
}