我正在使用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)
我在execute
命令中有正好等待状态的20个线程。我是否对设置做错了,因为我希望客户端返回,即使我的UDF中有任何异常,如果存在无限循环会发生什么?它会导致这种行为吗?
答案 0 :(得分:3)
如果不查看源代码,很难说出导致死锁的原因。您的AsyncClientPolicy看起来足够了。
无论如何,旧的AsyncClient类已经过时version 4已经过时了。 AerospikeClient类现在包括新的异步方法,它们的执行速度必须比旧的AsyncClient快。新的异步方法也支持Netty事件循环,并且始终以非阻塞模式运行。