我正在使用aeropike異步客戶端執行udf。客戶端已被初始化爲: -Aerospike Java異步庫似乎卡住了
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中有任何異常,如果有無限循環會發生什麼?它會導致這種行爲嗎?
更改爲同步客戶端解決了問題 –