# Async client blocking

**URL:** <https://discuss.aerospike.com/t/async-client-blocking/3695>\
**Category:** Java Client\
**Created:** [December 15, 2016, 6:55pm UTC](https://discuss.aerospike.com/t/async-client-blocking/3695 "2016-12-15T18:55:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anurag\_bhoumick](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@anurag\_bhoumick](https://discuss.aerospike.com/u/anurag_bhoumick)\
**Post date:** [December 15, 2016, 6:55pm UTC](https://discuss.aerospike.com/t/async-client-blocking/3695/1 "2016-12-15T18:55:11Z")

</div>

I am using the async client according to the example mentioned in [http://www.aerospike.com/docs/client/java/usage/async](http://www.aerospike.com/docs/client/java/usage/async)

I am using below get for read get(BatchPolicy policy, RecordArrayListener listener, Key keys)

However after making almost ~50000 requests, the threads go into a wate state. Below is the stack trace for one of the threads.

“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.(AsyncBatch.java:249) at com.aerospike.client.async.AsyncClient.get(AsyncClient.java:568)

Can to tell me why this might me happening or how to prevent this

---

<div class="post-metadata">

**Author:** ![meher](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/meher/32/1644_2.png) [@meher](https://discuss.aerospike.com/u/meher)\
**Post date:** [December 16, 2016, 5:02pm UTC](https://discuss.aerospike.com/t/async-client-blocking/3695/2 "2016-12-16T17:02:19Z")

</div>

The async client can deadlock when nested async commands are issued. To fix deadlock, define a task thread pool which offloads the async callback (onSuccess()) to a thread pool which frees up the selector thread to process other commands. Here is an example:

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

```

See online docs at [https://github.com/citrusleaf/aerospike-client-java/blob/master/client/src/com/aerospike/client/async/AsyncClientPolicy.java](https://github.com/citrusleaf/aerospike-client-java/blob/master/client/src/com/aerospike/client/async/AsyncClientPolicy.java)

---

<div class="post-metadata">

**Author:** ![dellmerca](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@dellmerca](https://discuss.aerospike.com/u/dellmerca)\
**Post date:** [July 13, 2017, 6:01am UTC](https://discuss.aerospike.com/t/async-client-blocking/3695/3 "2017-07-13T06:01:51Z")

</div>

A lock occurs when multiple processes try to access the same resource at the same time. A deadlock occurs when the waiting process is still holding on to another resource that the first needs before it can finish. A Java multithreaded program may suffer from the deadlock condition because the synchronized keyword causes the executing thread to block while waiting for the lock, or monitor , associated with the specified object. More on…[Java Deadloack](http://net-informations.com/java/cjava/deadlock.htm)

Dell

---

<div class="post-metadata">

**Author:** ![Deepikaa\_Subramaniam](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/deepikaa_subramaniam/32/1291_2.png) [@Deepikaa\_Subramaniam](https://discuss.aerospike.com/u/Deepikaa_Subramaniam)\
**Post date:** [October 31, 2019, 1:21am UTC](https://discuss.aerospike.com/t/async-client-blocking/3695/4 "2019-10-31T01:21:27Z")

</div>

I see similar issue, and the policy is already defined with a taskThreadPool. I am still seeing the deadlock issue when we take a jstack.
