Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/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
Amazon web services AWS Redis:JedisConnectionException:java.net.SocketException:打开的文件太多_Amazon Web Services_Redis_Tomcat8_Jedis - Fatal编程技术网

Amazon web services AWS Redis:JedisConnectionException:java.net.SocketException:打开的文件太多

Amazon web services AWS Redis:JedisConnectionException:java.net.SocketException:打开的文件太多,amazon-web-services,redis,tomcat8,jedis,Amazon Web Services,Redis,Tomcat8,Jedis,我已经使用AWS Elasticache配置了redis,并通过安装在AWS EC2上的tomcat将其连接起来 以下是我的代码: private JedisPool jedisPool = null; @PostConstruct private void initialiseJedisPools() { try { String redisHost = RESOURCES.getProperty("redis.master.host"); if(Ob

我已经使用AWS Elasticache配置了redis,并通过安装在AWS EC2上的tomcat将其连接起来

以下是我的代码:

private JedisPool jedisPool = null;

@PostConstruct
private void initialiseJedisPools() {
    try {
        String redisHost = RESOURCES.getProperty("redis.master.host");
        if(Objects.nonNull(redisHost)) {
            Integer redisPort = Integer.valueOf(RESOURCES.getProperty("redis.master.port"));
            jedisPool = new JedisPool(redisHost, redisPort);
        }
    } catch (NumberFormatException exception) {
        logger.error("Exception occurred while initialising jedis pool.", exception);
    }
}

public void addKey(String key, String value, Integer secondsToExpire) {
    if (Objects.nonNull(jedisPool)) {
        try (Jedis jedis = jedisPool.getResource()) {
            jedis.set(key, value);
            if (Objects.nonNull(secondsToExpire)) {
                jedis.expire(key, secondsToExpire.intValue());
            }
        } catch (JedisException jedisException) {
            logger.error("Exception thrown while adding key in cache.", jedisException);
        }
    }
}
我经常会遇到以下错误,我必须重新启动tomcat才能使其正常工作

redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
        at redis.clients.util.Pool.getResource(Pool.java:53)
        at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
        .
        .
        .
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Too many open files
        at redis.clients.jedis.Connection.connect(Connection.java:207)
        at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
        at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
        at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
        at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
        at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
        at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
        at redis.clients.util.Pool.getResource(Pool.java:49)
        ... 10 more
Caused by: java.net.SocketException: Too many open files
        at java.net.Socket.createImpl(Socket.java:460)
        at java.net.Socket.getImpl(Socket.java:520)
        at java.net.Socket.setReuseAddress(Socket.java:1449)
        at redis.clients.jedis.Connection.connect(Connection.java:174)
        ... 17 more
我已尝试为打开的文件增加
ulimit
,为
maxTotal
配置
fuldispoolconfig
maxIdle
minIdle
等,但没有成功


请提出建议。

我们过去也遇到过类似的问题,jedis连接错误为“java.net.SocketException:打开的文件太多”

这是因为绝地连接没有关闭

调用jedisPool.returnresource(绝地)或jedis.close()


tomcat被拒绝打开连接。您试图设置的
ulimit
可能不起作用。还要检查您是否正确返回到池的连接。使用try-with资源,可以正确返回连接。另外,尝试ulimit高达24000次,大约每10天出现一次错误,您可以检查ulimit是否生效吗<代码>cat/proc//limits当然是我做的。