0

我有以下 CouchBase 模板 Bean:

 @PostConstruct
public void initIt() throws Exception {
    if(couchbaseDisabled)
        return;
    couchbaseClient= new CouchbaseClient(
            bootstrapUris(Arrays.asList(hosts.split(","))),
            CouchbaseConstants.BUCKET,
            ""
    );
    couchbaseTemplate();
}



public void couchbaseTemplate() throws Exception {
    logger.info("Enabling CouchBase Template");
    couchbaseTemplate= new CouchbaseTemplate(couchbaseClient);
    //couchbaseTemplate.
}

@PreDestroy
public void cleanup() throws Exception {
    logger.info("Closing couchbase connection.");
    if (couchbaseClient != null) {
        couchbaseClient.shutdown();
        couchbaseTemplate=null;
        couchbaseClient=null;
    }
}

当服务器关闭时,我收到以下日志:

SEVERE: The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Jan 8, 2016 4:57:24 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@40c94525]) and a value of type [com.couchbase.client.deps.io.netty.util.internal.InternalThreadLocalMap] (value [com.couchbase.client.deps.io.netty.util.internal.InternalThreadLocalMap@5ddaa15d]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
Jan 8, 2016 4:57:24 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@40c94525]) and a value of type [com.couchbase.client.deps.io.netty.util.internal.InternalThreadLocalMap] (value [com.couchbase.client.deps.io.netty.util.internal.InternalThreadLocalMap@3c9810ce]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
Jan 8, 2016 4:57:24 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@40c94525]) and a value of type [com.couchbase.client.deps.io.netty.util.internal.InternalThreadLocalMap] (value [com.couchbase.client.deps.io.netty.util.internal.InternalThreadLocalMap@23776376]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
Jan 8, 2016 4:57:24 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@40c94525]) and a value of type [com.couchbase.client.deps.io.netty.util.internal.InternalThreadLocalMap] (value [com.couchbase.client.deps.io.netty.util.internal.InternalThreadLocalMap@7322ea2a]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
Jan 8, 2016 4:57:32 PM org.apache.coyote.http11.Http11Protocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-8099

在这里可以做什么?

4

1 回答 1

0

好的,所以您的应用程序中同时运行了 SDK 1.4.x 和 2.x(因为您com.couchbase.client:java-client的 pom 中有)。

线程泄漏消息来自后者。您必须在Cluster某处实例化 a(如 中com.couchbase.client.java.Cluster)。cluster.disconnect()确保在应用程序生命周期结束时通过调用(我猜是从一个方法来清理它@PreDestroy,就像你对 CouchbaseClient 所做的那样)。

如果您还创建了一个自定义CouchbaseEnvironment,您还必须通过调用正确关闭它(使用与集群清理相同的方法)environment.shutdownAsync().toBlocking().single()

确保使用最新版本的 2.x SDK,因为一些旧版本存在与关闭时适当的线程清理相关的错误(请参阅JCBC-773JVMCBC-251问题)。

于 2016-01-08T14:59:36.893 回答