diff --git a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXApplication.java b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXApplication.java index 8025bc7cdf8..29a1b794410 100644 --- a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXApplication.java +++ b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXApplication.java @@ -111,6 +111,7 @@ import er.extensions.foundation.ERXRuntimeUtilities; import er.extensions.foundation.ERXThreadStorage; import er.extensions.foundation.ERXTimestampUtilities; +import er.extensions.foundation.ERXValueUtilities; import er.extensions.localization.ERXLocalizer; import er.extensions.migration.ERXMigrator; import er.extensions.statistics.ERXStats; @@ -138,6 +139,7 @@ * @property er.extensions.ERXApplication.StatisticsLogRotationFrequency * @property er.extensions.ERXApplication.developmentMode * @property er.extensions.ERXApplication.developmentMode + * @property er.extensions.ERXApplication.enableERXShutdownHook * @property er.extensions.ERXApplication.fixCachingEnabled * @property er.extensions.ERXApplication.lowMemBufferSize * @property er.extensions.ERXApplication.memoryLowThreshold @@ -854,6 +856,11 @@ private String stringFromJar(String jar, String path) { } } } + + // You should not use ERXShutdownHook when deploying as servlet. + protected static boolean enableERXShutdownHook() { + return ERXProperties.booleanForKeyWithDefault("er.extensions.ERXApplication.enableERXShutdownHook", true); + } /** * Called when the application starts up and saves the command line @@ -863,6 +870,11 @@ private String stringFromJar(String jar, String path) { */ public static void main(String argv[], Class applicationClass) { setup(argv); + + if(enableERXShutdownHook()) { + ERXShutdownHook.initERXShutdownHook(); + } + WOApplication.main(argv, applicationClass); } @@ -1034,6 +1046,17 @@ private void reportErrors() { } } + /** + * This heuristic to determine if an application is deployed as servlet relays on the fact, + * that contextClassName() is set WOServletContext or ERXWOServletContext + * + * @return true if the application is deployed as servlet. + */ + public boolean isDeployedAsServlet() { + return contextClassName().contains("Servlet"); // i.e one of WOServletContext or ERXWOServletContext + } + + /** * Called prior to actually initializing the app. Defines framework load * order, class path order, checks patches etc. @@ -1047,9 +1070,12 @@ public static void setup(String[] argv) { ERXConfigurationManager.defaultManager().setCommandLineArguments(argv); ERXFrameworkPrincipal.setUpFrameworkPrincipalClass(ERXExtensions.class); // NSPropertiesCoordinator.loadProperties(); - ERXShutdownHook.useMe(); + + if(enableERXShutdownHook()) { + ERXShutdownHook.useMe(); + } } - + /** * Installs several bugfixes and enhancements to WODynamicElements. Sets the * Context class name to "er.extensions.ERXWOContext" if it is "WOContext". diff --git a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXShutdownHook.java b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXShutdownHook.java index 21b4feb2f7c..30992501d7d 100644 --- a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXShutdownHook.java +++ b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXShutdownHook.java @@ -29,6 +29,15 @@ * } * }; *

+ * + * + * CAUTION

+ * You should not use this class when deploying the application as a J2EE servlet as it may interfere with other servlets running in the same VM. + * To disable this feature you have to provide the following start parameter to the java VM: + * + * + * -Der.extensions.ERXApplication.enableERXShutdownHook=false + *
* * @author Maik Musall, maik@selbstdenker.ag * @@ -37,7 +46,8 @@ public abstract class ERXShutdownHook extends Thread { static final Set ALL_HOOKS = new HashSet(); - static { + public static void initERXShutdownHook() { + System.out.println( "WILL ADD SHUTDOWNHOOK" ); Runtime.getRuntime().addShutdownHook( new Thread() { @Override public void run() { diff --git a/Frameworks/Core/ERExtensions/Sources/er/extensions/foundation/ERXConfigurationManager.java b/Frameworks/Core/ERExtensions/Sources/er/extensions/foundation/ERXConfigurationManager.java index 657a56b6d33..b22b5cd5bdf 100644 --- a/Frameworks/Core/ERExtensions/Sources/er/extensions/foundation/ERXConfigurationManager.java +++ b/Frameworks/Core/ERExtensions/Sources/er/extensions/foundation/ERXConfigurationManager.java @@ -398,7 +398,7 @@ public String hostName() { } /** - * Checks if the application is deployed as a servlet. + * Checks if the application is may be deployed as a servlet. *

* The current implementation only checks if the application * is linked against JavaWOJSPServlet.framework.