You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2010/01/08 20:46:41 UTC
svn commit: r897310 - in
/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging:
JDKBugHacks.java Log4jLogger.java
Author: dkulp
Date: Fri Jan 8 19:46:40 2010
New Revision: 897310
URL: http://svn.apache.org/viewvc?rev=897310&view=rev
Log:
[CXF-1816] Copy some JDK hacks from Tomcat to try and get jars not to
lock.
Added:
cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/JDKBugHacks.java (with props)
Modified:
cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/Log4jLogger.java
Added: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/JDKBugHacks.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/JDKBugHacks.java?rev=897310&view=auto
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/JDKBugHacks.java (added)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/JDKBugHacks.java Fri Jan 8 19:46:40 2010
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.common.logging;
+
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.imageio.ImageIO;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+/**
+ * This is called from LogUtils as LogUtils is almost always one of the VERY
+ * first classes loaded in CXF so we can try and register to hacks/workarounds
+ * for various bugs in the JDK.
+ *
+ * Much of this is taken from work the Tomcat folks have done to find
+ * places where memory leaks and jars are locked and such.
+ * See:
+ * http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/
+ * core/JreMemoryLeakPreventionListener.java
+ *
+ */
+final class JDKBugHacks {
+ private JDKBugHacks() {
+ //not constructed
+ }
+
+ public static void doHacks() {
+ ClassLoader orig = Thread.currentThread().getContextClassLoader();
+ try {
+ //set to the topmost non-null so things that grab the context classloader
+ //won't get our classloader.
+ ClassLoader ncl = orig;
+ while (ncl.getParent() != null) {
+ ncl = ncl.getParent();
+ }
+ Thread.currentThread().setContextClassLoader(ncl);
+
+ try {
+ //Trigger a call to sun.awt.AppContext.getAppContext()
+ ImageIO.getCacheDirectory();
+ } catch (Throwable t) {
+ //ignore
+ }
+ try {
+ // Several components end up opening JarURLConnections without first
+ // disabling caching. This effectively locks the file.
+ // JAXB does this and thus affects us pretty badly.
+ // Doesn't matter that this JAR doesn't exist - just as long as
+ // the URL is well-formed
+ URL url = new URL("jar:file://dummy.jar!/");
+ URLConnection uConn = url.openConnection();
+ uConn.setDefaultUseCaches(false);
+ } catch (Throwable e) {
+ //ignore
+ }
+ try {
+ //DocumentBuilderFactory seems to SOMETIMES pin the classloader
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.newDocumentBuilder();
+ } catch (Throwable e) {
+ //ignore
+ }
+ // Several components end up calling:
+ // sun.misc.GC.requestLatency(long)
+ //
+ // Those libraries / components known to trigger memory leaks due to
+ // eventual calls to requestLatency(long) are:
+ // - javax.management.remote.rmi.RMIConnectorServer.start()
+ try {
+ Class<?> clazz = Class.forName("sun.misc.GC");
+ Method method = clazz.getDeclaredMethod("requestLatency",
+ new Class[] {Long.TYPE});
+ method.invoke(null, Long.valueOf(3600000));
+ } catch (Throwable e) {
+ //ignore
+ }
+ } finally {
+ Thread.currentThread().setContextClassLoader(orig);
+ }
+
+ }
+
+}
Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/JDKBugHacks.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/JDKBugHacks.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/Log4jLogger.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/Log4jLogger.java?rev=897310&r1=897309&r2=897310&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/Log4jLogger.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/common/logging/Log4jLogger.java Fri Jan 8 19:46:40 2010
@@ -52,6 +52,8 @@
private final org.apache.log4j.Logger log;
static {
+ JDKBugHacks.doHacks();
+
//older versions of log4j don't have TRACE, use debug
org.apache.log4j.Level t = org.apache.log4j.Level.DEBUG;
try {