diff --git a/src/main/java/org/elasticsearch/action/search/TransportMultiSearchAction.java b/src/main/java/org/elasticsearch/action/search/TransportMultiSearchAction.java index 32a6627c55e..0a0c5d357d4 100644 --- a/src/main/java/org/elasticsearch/action/search/TransportMultiSearchAction.java +++ b/src/main/java/org/elasticsearch/action/search/TransportMultiSearchAction.java @@ -27,6 +27,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.concurrent.AtomicArray; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.BaseTransportRequestHandler; import org.elasticsearch.transport.TransportChannel; @@ -56,16 +57,14 @@ public class TransportMultiSearchAction extends TransportAction responses = new AtomicArray(request.requests().size()); + final AtomicInteger counter = new AtomicInteger(responses.length()); + for (int i = 0; i < responses.length(); i++) { final int index = i; searchAction.execute(request.requests().get(i), new ActionListener() { @Override public void onResponse(SearchResponse searchResponse) { - synchronized (responses) { - responses[index] = new MultiSearchResponse.Item(searchResponse, null); - } + responses.set(index, new MultiSearchResponse.Item(searchResponse, null)); if (counter.decrementAndGet() == 0) { finishHim(); } @@ -73,16 +72,14 @@ public class TransportMultiSearchAction extends TransportAction