我正在尝试使用异步java客户端进行异步读取。我指的是提到的例子 http://www.aerospike.com/docs/client/java/usage/async
我在下面使用获取阅读 get(BatchPolicy策略,RecordArrayListener侦听器,Key []键)
这几乎没有请求,但是在发出大约50000个请求之后,线程进入无限期等待状态。下面是其中一个线程的堆栈跟踪。
"pool-11-thread-1" - Thread t@56
java.lang.Thread.State: WAITING
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <737890e3> (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 java.util.concurrent.ArrayBlockingQueue.take(ArrayBlockingQueue.java:403)
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.AsyncMul tiExecutor.execute(AsyncMultiExecutor.java:36)
at com.aerospike.client.async.AsyncBatch$GetArrayExecutor.<init>(AsyncBatch.java:249)
at com.aerospike.client.async.AsyncClient.get(AsyncClient.java:568)
任何人都可以建议为什么会发生这种情况或者如何防止这种情况发生。
答案 0 :(得分:1)
发出嵌套异步命令时,异步客户端可能会死锁。要修复死锁,请定义一个任务线程池,它将异步回调(onSuccess())卸载到一个线程池,该线程池释放选择器线程以处理其他命令。这是一个例子:
AsyncClientPolicy policy = new AsyncClientPolicy();
policy.asyncTaskThreadPool = Executors.newCachedThreadPool(new ThreadFactory() {
public final Thread newThread(Runnable runnable) {
Thread thread = new Thread(runnable);
thread.setDaemon(true);
return thread;
}
});
AsyncClient client = new AsyncClient(policy, host, port);
上的在线文档