Description
We should call getUpdatedQueryContext() in while loop to make sure latest status is available after each "listener.wait(waitMillisPerCheck)"
if (totalWaitTime > 0 && !queryCtx.getStatus().executed() && !queryCtx.getStatus().finished()) { log.info("Registering for query {} completion notification", ctx.getQueryHandleString()); queryCtx.getSelectedDriver().registerForCompletionNotification(handle, totalWaitTime, listener); try { // We will wait for a few millis at a time until we reach max required wait time and also check the state // each time we come out of the wait. // This is done because the registerForCompletionNotification and query execution completion can happen // parallely especailly in case of drivers like JDBC and in that case completion notification may not be // received by this listener. So its better to break the wait into smaller ones. long waitMillisPerCheck = totalWaitTime/10; waitMillisPerCheck = (waitMillisPerCheck > 500) ? 500 : waitMillisPerCheck; // Lets keep max as 500 long totalWaitMillisSoFar = 0; synchronized (listener) { while (totalWaitMillisSoFar < totalWaitTime && !queryCtx.getStatus().executed() && !queryCtx.getStatus().finished()) { listener.wait(waitMillisPerCheck); totalWaitMillisSoFar += waitMillisPerCheck; } } } catch (InterruptedException e) { log.info("{} query completion notification wait interrupted", queryCtx.getQueryHandleString()); } }