redis / lettuce

Advanced Java Redis client for thread-safe sync, async, and reactive usage. Supports Cluster, Sentinel, Pipelining, and codecs.
https://lettuce.io
MIT License
5.37k stars 964 forks source link

when using with tomcat, it will block tomcat's stoping #200

Closed KarlManong closed 8 years ago

KarlManong commented 8 years ago

Version: 4.0.2.Final com.lambdaworks.redis.AbstractRedisClient has a field called "timer"(instance of HashedWheelTimer) which would created a executor. However, the executor has not be shutdown gracefully, so it would casuse tomcat block when trying to stop the tomcat process(bootstrap).

So i have to do someting tricky when shutdown the tomcat in my web app:

        try {
            Field field = AbstractRedisClient.class.getDeclaredField("timer");
            field.setAccessible(true);
            ((HashedWheelTimer) field.get(client)).stop();
        } catch (NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();
        }

plz correct me if i am wrong.

KarlManong commented 8 years ago

I found it.

mp911de commented 8 years ago

The timer is stopped in any case if the shutdown(...) method is called. See https://github.com/mp911de/lettuce/blob/4.0.1.Final/src/main/java/com/lambdaworks/redis/AbstractRedisClient.java#L238