2016-12-15 92 views
2

我想使用async java客戶端進行異步讀取。我指的是在 http://www.aerospike.com/docs/client/java/usage/asyncAerospike Java異步客戶端阻止

我使用下面獲取閱讀 GET(BatchPolicy政策,RecordArrayListener監聽器,按鍵[]鍵)

這正常工作與幾個請求,但是製作後幾乎提到的例子〜50000個請求,線程進入無限期等待狀態。以下是其中一個線程的堆棧跟蹤。

"pool-11-thread-1" - Thread [email protected] 
    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) 

任何人都可以提出爲什麼這可能會發生或如何防止這種情況。

回答

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); 

見在線文檔在https://github.com/citrusleaf/aerospike-client-java/blob/master/client/src/com/aerospike/client/async/AsyncClientPolicy.java

+0

嘿,這工作。我使用固定大小的線程池Executors.newFixedThreadPool(asyncClientPolicy.asyncMaxCommands) 在AsyncClientPolicy中,我們有一個配置asyncSelectorThreads。它沒有在文檔中給出關於它的更多細節。你能否建議應該設置什麼樣的最佳值? –