박종현
2016-11-15 02:05:03 UTC
Hi, I'm using Jedis from a multi threaded environment and I'm getting this
error code
Exception in thread "main"
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 HelloRedis.<init>(HelloRedis.java:22)
at HelloRedis.main(HelloRedis.java:38)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException:
java.net.ConnectException: Connection refused: connect
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)
... 3 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(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:184)
... 10 more
Here is my Jedis test code.
import java.util.ArrayList;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
public class HelloRedis implements Runnable{
int seq;
Jedis jedis;
static JedisPool pool;
static JedisPoolConfig config;
String str = "@";
public HelloRedis(int seq){
this.seq = seq;
this.jedis = pool.getResource();
}
public static void main(String args[]) {
config = new JedisPoolConfig();
config.setMaxTotal(1000000);
config.setMaxIdle(1000000);
pool = new JedisPool(config, "localhost", 6379, 0);
long startTime = System.currentTimeMillis();
ArrayList<Thread> threads = new ArrayList<Thread>();
for(int i=0; i<100000; i++) {
Thread t = new Thread(new HelloRedis(i));
t.start();
threads.add(t);
}
for(int j = 0; j<threads.size(); j++){
Thread t = threads.get(j);
try{
t.join();
}catch(Exception e){
e.printStackTrace();
}
}
long endTime = System.currentTimeMillis();
System.out.println(":::::::::"+(endTime-startTime));
}
@Override
public void run() {
for(int i=0; i < 10000; i++){
jedis.set(seq+"key"+i, i+str);
}
jedis.close();
}
}
I set the number of maxclients is 10,000,000 in redis.conf file.
I wonder why this code occur error although I set that Jedis pool size is
bigger than the number of threads.
I'm using Redis 3.2.1, Jedis 2.9.0 and commons-pool2 2.4.2
error code
Exception in thread "main"
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 HelloRedis.<init>(HelloRedis.java:22)
at HelloRedis.main(HelloRedis.java:38)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException:
java.net.ConnectException: Connection refused: connect
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)
... 3 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(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:184)
... 10 more
Here is my Jedis test code.
import java.util.ArrayList;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
public class HelloRedis implements Runnable{
int seq;
Jedis jedis;
static JedisPool pool;
static JedisPoolConfig config;
String str = "@";
public HelloRedis(int seq){
this.seq = seq;
this.jedis = pool.getResource();
}
public static void main(String args[]) {
config = new JedisPoolConfig();
config.setMaxTotal(1000000);
config.setMaxIdle(1000000);
pool = new JedisPool(config, "localhost", 6379, 0);
long startTime = System.currentTimeMillis();
ArrayList<Thread> threads = new ArrayList<Thread>();
for(int i=0; i<100000; i++) {
Thread t = new Thread(new HelloRedis(i));
t.start();
threads.add(t);
}
for(int j = 0; j<threads.size(); j++){
Thread t = threads.get(j);
try{
t.join();
}catch(Exception e){
e.printStackTrace();
}
}
long endTime = System.currentTimeMillis();
System.out.println(":::::::::"+(endTime-startTime));
}
@Override
public void run() {
for(int i=0; i < 10000; i++){
jedis.set(seq+"key"+i, i+str);
}
jedis.close();
}
}
I set the number of maxclients is 10,000,000 in redis.conf file.
I wonder why this code occur error although I set that Jedis pool size is
bigger than the number of threads.
I'm using Redis 3.2.1, Jedis 2.9.0 and commons-pool2 2.4.2
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+***@googlegroups.com.
To post to this group, send email to redis-***@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+***@googlegroups.com.
To post to this group, send email to redis-***@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.