多次访问Redis Q时出现资源错误

时间:2012-10-26 07:00:08

标签: java android redis socketexception jedis

这是我用来从redis Q访问值的代码。

Jedis jedis = null;
try
{
int maxActive = 1000;
int maxIdle = 5;
int minIdle = 1;
long maxWait = 5000;

JedisPoolConfig config = new JedisPoolConfig ();
config.setMaxActive (maxActive);
config.setMaxIdle (maxIdle);
config.setMinIdle(minIdle);
config.setMaxWait (maxWait);
config.setTestOnBorrow (false);
pool = new JedisPool (config, RedisServerURL) ;

jedis = pool.getResource();
jedis.getClient().setTimeoutInfinite();
redisQMesssage = jedis.rpop(RedisQ);
//my code           
}
catch (Exception e) 
{
e.printStackTrace();
}
finally{
pool.returnResource(jedis); 
pool.destroy();
}  

我在3个工作线程中有上面的代码。我打电话给3工人线程40次(完全) 很少1/5我收到错误“无法从池中获取资源(SocketTimeoutException :)”

堆栈跟踪

redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:22)
at Workers.Worker1.met1(Worker1.java:124)
at Workers.Worker1.work(Worker1.java:108)
at org.gearman.impl.worker.WorkerConnectionController$3.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)  

Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out
at redis.clients.jedis.Connection.connect(Connection.java:124)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:54)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1657)
at redis.clients.jedis.JedisPool$JedisFactory.makeObject(JedisPool.java:63)
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1188)
at redis.clients.util.Pool.getResource(Pool.java:20)
... 6 more  

Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at redis.clients.jedis.Connection.connect(Connection.java:119)
... 11 more  

请帮帮我。

0 个答案:

没有答案