我有一个运行多个线程的tomcat - spring4.2 应用程序。每个线程仅从一个队列中出列,但是分配给一个队列的线程不止一个。
事情开始很好,但在几个小时/〜500k出队操作后,我发现线程出队的速度非常慢。
在 jvisualvm 中,我看到了橙色的线程,即 park 线程转储如下:
"EMLT_2" - Thread t@64
java.lang.Thread.State: WAITING
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <2cf42d7> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at org.apache.commons.pool2.impl.LinkedBlockingDeque.takeFirst(LinkedBlockingDeque.java:583)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:442)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
at redis.clients.util.Pool.getResource(Pool.java:48)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:86)
at com.mycomp.sam.processors.SimpleDequeuer.dequeue(SimpleDequeuer.java:25)
at com.mycomp.sam.processors.EMLT.run(EMLT.java:29)
at java.lang.Thread.run(Thread.java:745)
Locked ownable synchronizers:
- None
"EMLT_1" - Thread t@63
java.lang.Thread.State: WAITING
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <2cf42d7> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at org.apache.commons.pool2.impl.LinkedBlockingDeque.takeFirst(LinkedBlockingDeque.java:583)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:442)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
at redis.clients.util.Pool.getResource(Pool.java:48)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:86)
at com.mycomp.sam.processors.SimpleDequeuer.dequeue(SimpleDequeuer.java:25)
at com.mycomp.sam.processors.EMLT.run(EMLT.java:29)
at java.lang.Thread.run(Thread.java:745)
Locked ownable synchronizers:
- None
出队方法是:
public String dequeue(String queue) {
try (Jedis jedis = jedispool.getResource()) {
List<String> str = jedis.blpop(10, queue);
if(str!=null){
return str.get(1);
}
else
return null;
}
}
将欣赏投入。该应用程序在重新启动后再次运行良好一段时间。池配置:
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="10" />
<property name="maxTotal" value="70" />
<property name="minIdle" value="10" />
</bean>
<bean id="jedispool" class="redis.clients.jedis.JedisPool">
<constructor-arg name="poolConfig" ref="poolConfig" />
<constructor-arg name="host" value="${REDIS_HOST}" />
<constructor-arg name="port" value="6379" />
</bean>