diff --git a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/client/Duniter4jClientImpl.java b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/client/Duniter4jClientImpl.java index 5bed8bd66e393df212855b15230a0a25a7ef6e7a..46dd607bac5703b30ab2a884be5798d91d811d23 100644 --- a/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/client/Duniter4jClientImpl.java +++ b/cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/client/Duniter4jClientImpl.java @@ -1074,25 +1074,26 @@ public class Duniter4jClientImpl implements Duniter4jClient { public void safeExecuteRequest(ActionRequestBuilder<?, ?, ?> request, boolean wait) { // Execute in a pool - if (!wait) { - boolean acceptedInPool = false; - while(!acceptedInPool) + ListenableActionFuture<?> actionFuture = null; + boolean acceptedInPool = false; + while(!acceptedInPool) { + try { + actionFuture = request.execute(); + acceptedInPool = true; + } + catch(EsRejectedExecutionException e) { + // not accepted, so wait try { - request.execute(); - acceptedInPool = true; + Thread.sleep(1000); // 1s } - catch(EsRejectedExecutionException e) { - // not accepted, so wait - try { - Thread.sleep(1000); // 1s - } - catch(InterruptedException e2) { - // silent - } + catch(InterruptedException e2) { + // silent } - - } else { - request.execute().actionGet(); + } + } + // Wait end of action, if need + if (wait && actionFuture != null) { + actionFuture.actionGet(); } } }