Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java中使用莴苣API的web应用程序中使用Redis?_Java_Redis_Lettuce - Fatal编程技术网

如何在Java中使用莴苣API的web应用程序中使用Redis?

如何在Java中使用莴苣API的web应用程序中使用Redis?,java,redis,lettuce,Java,Redis,Lettuce,我想在web应用程序中使用Redis。为此,我在侦听器中使用了一个静态的StatefulRedisConnection,并在其他类中使用了它。为了执行Redis命令,我用创建连接的相同方法创建了一个RedisCommands实例。我阅读了莴苣的文档,发现我使用的方法是正确的。但是当我想终止我的程序时,tomcat警告我内存泄漏,但我找不到问题 我的代码: public class ContextListener implements ServletContextListener { public

我想在web应用程序中使用Redis。为此,我在侦听器中使用了一个静态的
StatefulRedisConnection
,并在其他类中使用了它。为了执行Redis命令,我用创建连接的相同方法创建了一个
RedisCommands
实例。我阅读了莴苣的文档,发现我使用的方法是正确的。但是当我想终止我的程序时,tomcat警告我内存泄漏,但我找不到问题

我的代码:

public class ContextListener implements ServletContextListener {
public static RedisClient redisClient;
public static StatefulRedisConnection<String, String> connection;
public static RedisCommands<String, String> redis;

public void contextInitialized(ServletContextEvent sce) {
    redisClient = new RedisClient(RedisURI.create("redis://localhost:6379"));
    connection = redisClient.connect();
    redis = connection.sync();
}

public void contextDestroyed(ServletContextEvent sce) {
    redis.close();
    connection.close();
    redisClient.shutdown();
}

你能在Tomcat中发布内存泄漏消息的详细信息吗?上面的代码看起来不错,
redis.close()
connection.close()
的作用相同,因此无需同时调用这两个方法。@mp911de Tomcat犯了一个同样严重的错误,并告知Netty线程不会终止。我搜索了一下,发现了一个关于这个问题的问题,告诉我Netty线程不是守护进程线程,所以它们保持进程打开。请注意,wg/莴苣不再被维护。Github回购协议为mp911de/REACT。在调用redisClient.shutdown()之后,你能发布堆栈跟踪吗?@mp911de我已经添加了堆栈跟踪。你能在Tomcat中发布内存泄漏消息的详细信息吗?上面的代码看起来不错,
redis.close()
connection.close()
的作用相同,因此无需同时调用这两个方法。@mp911de Tomcat犯了一个同样严重的错误,并告知Netty线程不会终止。我搜索了一下,发现了一个关于这个问题的问题,告诉我Netty线程不是守护进程线程,所以它们保持进程打开。请注意,wg/莴苣不再被维护。Github回购协议为mp911de/REACT。您能否在调用
redisClient.shutdown()
之后立即发布堆栈跟踪?@mp911de我已经添加了堆栈跟踪。
    /usr/local/apache-tomcat-8.0.26/bin/catalina.sh stop
03-Dec-2015 12:49:40.992 INFO [main] org.apache.catalina.core.StandardServer.await A valid shutdown command was received via the shutdown port. Stopping the Server instance.
03-Dec-2015 12:49:40.993 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8080"]
03-Dec-2015 12:49:41.049 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-nio-8009"]
03-Dec-2015 12:49:41.102 INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service Catalina
03-Dec-2015 12:49:41.112 WARNING [localhost-startStop-2] com.lambdaworks.redis.RedisChannelHandler.close Connection is already closed
03-Dec-2015 12:49:43.342 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@2e242d5c]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@3dbe5969]) 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.
03-Dec-2015 12:49:43.342 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@2e242d5c]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@3f755d05]) 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.
03-Dec-2015 12:49:43.342 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@2e242d5c]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@30b4d97a]) 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.
03-Dec-2015 12:49:43.342 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@2e242d5c]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@7f0eab14]) 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.
03-Dec-2015 12:49:43.343 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@2e242d5c]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@7f56b45e]) 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.
03-Dec-2015 12:49:43.343 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@2e242d5c]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@6a5e43c4]) 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.
03-Dec-2015 12:49:43.343 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@2e242d5c]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@7c3738fc]) 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.
03-Dec-2015 12:49:43.343 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@2e242d5c]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@766b6a65]) 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.
03-Dec-2015 12:49:43.343 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@2e242d5c]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@3cd5d4b2]) 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.
03-Dec-2015 12:49:43.343 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@2e242d5c]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@240df08f]) 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.
03-Dec-2015 12:49:43.344 SEVERE [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@2e242d5c]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@6138cc2a]) 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.
03-Dec-2015 12:49:43.352 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"]
03-Dec-2015 12:49:43.454 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"]
03-Dec-2015 12:49:43.470 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"]
03-Dec-2015 12:49:43.470 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"]