最近使用redis队列实现抢红包,在使用jmeter测试时发现1000个线程0s并发抢红包出现connect refused错误,但是500个10s就正常。源代码如下
private static void initialPool() {
try {
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxActive(1024);
config.setMaxIdle(200);
config.setMaxWait(10000);
config.setTestOnBorrow(false);
pool = new JedisPool(config, IP, PORT, 10000);
} catch (Exception e) {
logger.error("create JedisPool error : " + e);
}
}
private static synchronized void poolInit() {
if (pool == null) {
initialPool();
}
}
public synchronized static Jedis getJedis() {
if (pool == null) {
poolInit();
}
Jedis jedis = null;
try {
if (pool != null) {
jedis = pool.getResource();
}
} catch (Exception e) {