From 384931d92ebb40cc90bd0cc02a96296c9584666a Mon Sep 17 00:00:00 2001 From: Robin Bygrave Date: Thu, 25 Apr 2013 16:54:18 +1200 Subject: [PATCH] Fix for Issue 18 - Use property autofetch.garbageCollectionOnShutdown to control GC on shutdown behavior --- .../avaje/ebean/config/AutofetchConfig.java | 30 +++++++++++++++++-- .../autofetch/DefaultAutoFetchManager.java | 7 +++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/avaje/ebean/config/AutofetchConfig.java b/src/main/java/com/avaje/ebean/config/AutofetchConfig.java index b9b8addbc..26601ca09 100644 --- a/src/main/java/com/avaje/ebean/config/AutofetchConfig.java +++ b/src/main/java/com/avaje/ebean/config/AutofetchConfig.java @@ -24,6 +24,8 @@ public class AutofetchConfig { private int profileUpdateFrequency = 60; private int garbageCollectionWait = 100; + + private boolean garbageCollectionOnShutdown; public AutofetchConfig() { } @@ -207,6 +209,28 @@ public class AutofetchConfig { this.garbageCollectionWait = garbageCollectionWait; } + + /** + * Return true if GC should be trigger on shutdown. + *

+ * Autofetch profiling information is collected as part of garbage collection. + *

+ */ + public boolean isGarbageCollectionOnShutdown() { + return garbageCollectionOnShutdown; + } + + /** + * Set to true if you want GC to trigger on shutdown. + *

+ * This would be done if you want to try and collect Autofetch profiling information + * on shutdown. + *

+ */ + public void setGarbageCollectionOnShutdown(boolean garbageCollectionOnShutdown) { + this.garbageCollectionOnShutdown = garbageCollectionOnShutdown; + } + /** * Load the settings from the properties file. */ @@ -215,10 +239,10 @@ public class AutofetchConfig { logDirectory = p.get("autofetch.logDirectory", null); queryTuning = p.getBoolean("autofetch.querytuning", false); queryTuningAddVersion = p.getBoolean("autofetch.queryTuningAddVersion", false); - + garbageCollectionOnShutdown = p.getBoolean("autofetch.garbageCollectionOnShutdown", false); + profiling = p.getBoolean("autofetch.profiling", false); - mode = p - .getEnum(AutofetchMode.class, "autofetch.implicitmode", AutofetchMode.DEFAULT_ONIFEMPTY); + mode = p.getEnum(AutofetchMode.class, "autofetch.implicitmode", AutofetchMode.DEFAULT_ONIFEMPTY); profilingMin = p.getInt("autofetch.profiling.min", 1); profilingBase = p.getInt("autofetch.profiling.base", 10); diff --git a/src/main/java/com/avaje/ebeaninternal/server/autofetch/DefaultAutoFetchManager.java b/src/main/java/com/avaje/ebeaninternal/server/autofetch/DefaultAutoFetchManager.java index 0443d99e4..8291ffe3c 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/autofetch/DefaultAutoFetchManager.java +++ b/src/main/java/com/avaje/ebeaninternal/server/autofetch/DefaultAutoFetchManager.java @@ -68,6 +68,8 @@ public class DefaultAutoFetchManager implements AutoFetchManager, Serializable { private transient boolean queryTuningAddVersion; + private transient boolean garbageCollectionOnShutdown; + private transient AutofetchMode mode; /** @@ -93,6 +95,7 @@ public class DefaultAutoFetchManager implements AutoFetchManager, Serializable { AutofetchConfig autofetchConfig = serverConfig.getAutofetchConfig(); + garbageCollectionOnShutdown = autofetchConfig.isGarbageCollectionOnShutdown(); queryTuning = autofetchConfig.isQueryTuning(); queryTuningAddVersion = autofetchConfig.isQueryTuningAddVersion(); profiling = autofetchConfig.isProfiling(); @@ -269,10 +272,10 @@ public class DefaultAutoFetchManager implements AutoFetchManager, Serializable { *

*/ public void shutdown() { - //if (useFileLogging) { + if (garbageCollectionOnShutdown) { collectUsageViaGC(-1); serialize(); - //} + } } /**