为防止内存泄漏,JDBC驱动程序已被强制取消注册

时间:2011-10-13 01:47:07

标签: jdbc memory-leaks

当我停止tomcat7.0时,我得到了这个。我无法解决它。任何帮助将不胜感激。

SEVERE: The web application [/marketservice] registered the JDBC driver[oracle.jdbc.driver.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
2011-10-13 9:11:27 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/marketservice] appears to have started a thread named [FileWatchdog] but has failed to stop it. This is very likely to create a memory leak.
2011-10-13 9:11:27 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/marketservice] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.
2011-10-13 9:11:27 org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/marketservice] created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.ContainerImpl$10] (value [com.opensymphony.xwork2.inject.ContainerImpl$10@e24fa8]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@1dba740]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 
2011-10-13 9:11:27 org.apache.coyote.AbstractProtocolHandler stop
INFO: Stopping ProtocolHandler ["http-bio-8080"]
2011-10-13 9:11:27 org.apache.coyote.AbstractProtocolHandler stop
INFO: Stopping ProtocolHandler ["ajp-bio-8009"]

1 个答案:

答案 0 :(得分:1)

我知道你的话题不再是全新的,但是任何方式我都会遇到与WatchDog相同的问题

(具有JDBC连接的部分已经解决:link to Tomcat wiki

  

似乎已经启动了一个名为[FileWatchdog]但未能阻止它的线程。这很可能会造成内存泄漏。

他们努力在log4j link to log4j bug parade

的下一个版本中修复它

但我认为有办法解决。我像这样开始“WatchDog”:

@PostConstruct  
private void initLogging(File log4JConfig) {

    if (loggingExecutor == null) {
        LogManager.resetConfiguration();
        XMLWatchdog xdog = new XMLWatchdog(log4JConfig.getAbsolutePath());
        loggingExecutor = Executors.newSingleThreadScheduledExecutor();

        loggingExecutor.scheduleAtFixedRate(xdog, 0, 5, TimeUnit.MINUTES);
        Logger logger = Logger.getLogger(ConfigurationService.class);
        logger.info("Logging is initialized with the following configuration file: " + log4JConfig.getAbsolutePath());
    } else {
        logger.info("Logger is already ruinning");
    }

}

/**
 * Nasty bug:
 * 
 * https://issues.apache.org/bugzilla/show_bug.cgi?id=4913
 * 
 * 
 * @author Johannes.Hoehne
 * 
 */
private static class XMLWatchdog extends FileWatchdog {

    XMLWatchdog(String filename) {
        super(filename);
        setName("LogFileChecker");
    }

    public void doOnChange() {
        new DOMConfigurator().doConfigure(filename, LogManager.getLoggerRepository());
    }

    @Override
    public void run() {
        checkAndConfigure();
    }
}

之后再次停止它

    @PreDestroy
public void shutDownLogger() {
    logger.info("Will shut down logger task " + loggingExecutor);
    loggingExecutor.shutdown();
}