Aerospike Java异步库似乎卡住了
作者:互联网
我正在使用aeropike异步客户端执行udf.客户端已初始化为:-
try {
asyncClientPolicy.maxThreads = 40;
asyncClientPolicy.asyncMaxCommands = 20;
asyncClientPolicy.maxSocketIdle = 13;
asyncClientPolicy.asyncMaxCommandAction = MaxCommandAction.BLOCK;
asyncClientPolicy.asyncSelectorThreads = 7;
asyncClientPolicy.asyncTaskThreadPool = Executors.newFixedThreadPool(20, new ThreadFactory() {
public final Thread newThread(Runnable runnable) {
Thread thread = new Thread(runnable);
thread.setDaemon(true);
return thread;
}
});
}
所以我有20个线程来处理回调.一段时间后,我发现我的程序没有任何进展,表明死锁/饥饿. Jstack给我以下结果:-
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000064048f338> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
at java.util.concurrent.ArrayBlockingQueue.take(ArrayBlockingQueue.java:374)
at com.aerospike.client.async.AsyncCluster$BlockBufferQueue.getByteBuffer(AsyncCluster.java:114)
at com.aerospike.client.async.AsyncCluster.getByteBuffer(AsyncCluster.java:68)
at com.aerospike.client.async.AsyncCommand.execute(AsyncCommand.java:59)
at com.aerospike.client.async.AsyncClient.execute(AsyncClient.java:949)
at main.java.labs.RuleEngineAerospikeConnection.updatePositiveSegmentsUDF(RuleEngineAerospikeConnection.java:217)
at main.java.labs.Segment$ProductChecker.onSuccess(Segment.java:346)
at com.aerospike.client.async.AsyncRead.onSuccess(AsyncRead.java:149)
at com.aerospike.client.async.AsyncCommand.finish(AsyncCommand.java:293)
at com.aerospike.client.async.AsyncSingleCommand.read(AsyncSingleCommand.java:59)
at com.aerospike.client.async.AsyncCommand.run(AsyncCommand.java:261)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
我刚好有20个线程处于等待状态,都在execute命令上.我在设置上做错什么了吗,因为我希望客户端返回,即使UDF中存在任何异常,如果存在无限循环,也会发生什么情况?会导致这种行为吗?
解决方法:
不查看源代码就很难说是什么导致了死锁.您的AsyncClientPolicy看起来足够.
无论如何,旧的AsyncClient类自version 4开始就已过时.AerospikeClient类现在包括新的异步方法,这些方法的执行速度必须比旧的AsyncClient快.新的异步方法还支持Netty事件循环,并且始终在非阻塞模式下运行.
标签:aerospike,java 来源: https://codeday.me/bug/20191111/2017649.html