diff options
Diffstat (limited to 'jdisc_core')
-rw-r--r-- | jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdog.java | 7 | ||||
-rw-r--r-- | jdisc_core/src/test/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdogTest.java | 3 |
2 files changed, 7 insertions, 3 deletions
diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdog.java b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdog.java index 90e2049a868..c6355c93648 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdog.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdog.java @@ -67,7 +67,7 @@ class ActiveContainerDeactivationWatchdog implements ActiveContainerMetrics, Aut WATCHDOG_FREQUENCY.getSeconds(), WATCHDOG_FREQUENCY.getSeconds(), TimeUnit.SECONDS); - this.scheduler.scheduleAtFixedRate(System::gc, + this.scheduler.scheduleAtFixedRate(ActiveContainerDeactivationWatchdog::triggerGc, GC_TRIGGER_FREQUENCY.getSeconds(), GC_TRIGGER_FREQUENCY.getSeconds(), TimeUnit.SECONDS); @@ -121,6 +121,11 @@ class ActiveContainerDeactivationWatchdog implements ActiveContainerMetrics, Aut } } + private static void triggerGc() { + System.gc(); + System.runFinalization(); // this is required to trigger enqueuing of phantom references on some Linux systems + } + private void enforceDestructionOfGarbageCollectedContainers() { ActiveContainerPhantomReference reference; while ((reference = (ActiveContainerPhantomReference) garbageCollectedContainers.poll()) != null) { diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdogTest.java b/jdisc_core/src/test/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdogTest.java index 05207728c88..a618b82c5ec 100644 --- a/jdisc_core/src/test/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdogTest.java +++ b/jdisc_core/src/test/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdogTest.java @@ -6,7 +6,6 @@ import com.yahoo.jdisc.ResourceReference; import com.yahoo.jdisc.statistics.ActiveContainerMetrics; import com.yahoo.jdisc.test.TestDriver; import com.yahoo.test.ManualClock; -import org.junit.Ignore; import org.junit.Test; import java.lang.ref.WeakReference; @@ -69,7 +68,6 @@ public class ActiveContainerDeactivationWatchdogTest { } @Test - @Ignore("JVM does not give any guarantee when phantom references will be enqueued to reference queues") public void deactivated_container_destructed_if_its_reference_counter_is_nonzero() { ExecutorMock executor = new ExecutorMock(); ActiveContainerDeactivationWatchdog watchdog = @@ -87,6 +85,7 @@ public class ActiveContainerDeactivationWatchdogTest { WeakReference<ActiveContainer> containerWeakReference = new WeakReference<>(container); container = null; // make container instance collectable by GC System.gc(); + System.runFinalization(); // this is required to trigger enqueuing of phantom references on some Linux systems assertNull("Container is not GCed - probably because the watchdog has a concrete reference to it", containerWeakReference.get()); |