From dd93ebbe0da1925b1573d06b7600e8e2e6062aad Mon Sep 17 00:00:00 2001 From: Nikita Date: Mon, 26 Sep 2016 11:25:38 +0300 Subject: [PATCH] CommandAsyncService.get method optimization --- .../redisson/command/CommandAsyncService.java | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/redisson/src/main/java/org/redisson/command/CommandAsyncService.java b/redisson/src/main/java/org/redisson/command/CommandAsyncService.java index 2433fd0b6..ebeaebc4b 100644 --- a/redisson/src/main/java/org/redisson/command/CommandAsyncService.java +++ b/redisson/src/main/java/org/redisson/command/CommandAsyncService.java @@ -118,26 +118,28 @@ public class CommandAsyncService implements CommandAsyncExecutor { @Override public V get(RFuture future) { - final CountDownLatch l = new CountDownLatch(1); - future.addListener(new FutureListener() { - @Override - public void operationComplete(Future future) throws Exception { - l.countDown(); + if (!future.isDone()) { + final CountDownLatch l = new CountDownLatch(1); + future.addListener(new FutureListener() { + @Override + public void operationComplete(Future future) throws Exception { + l.countDown(); + } + }); + + boolean interrupted = false; + while (!future.isDone()) { + try { + l.await(); + } catch (InterruptedException e) { + interrupted = true; + } } - }); - - boolean interrupted = false; - while (!future.isDone()) { - try { - l.await(); - } catch (InterruptedException e) { - interrupted = true; + + if (interrupted) { + Thread.currentThread().interrupt(); } } - - if (interrupted) { - Thread.currentThread().interrupt(); - } // commented out due to blocking issues up to 200 ms per minute for each thread // future.awaitUninterruptibly();