我正在尝试使用异步java客户端进行异步读取。我指的是http://www.aerospike.com/docs/client/java/usage/async中提到的示例
我使用下面的get读取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)
有没有人能建议我为什么会发生这种情况或者如何防止这种情况发生。
发布于 2016-12-17 01:01:01
发出嵌套异步命令时,异步客户端可能会死锁。要修复死锁,请定义一个任务线程池,它将异步回调(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);
https://stackoverflow.com/questions/41158640
复制相似问题