diff --git a/src/main/java/net/spy/memcached/internal/AbstractListenableFuture.java b/src/main/java/net/spy/memcached/internal/AbstractListenableFuture.java index fd0b4e970..23c54bdce 100644 --- a/src/main/java/net/spy/memcached/internal/AbstractListenableFuture.java +++ b/src/main/java/net/spy/memcached/internal/AbstractListenableFuture.java @@ -141,15 +141,22 @@ protected void notifyListeners() { * @param future the future to pass on to the listeners. */ protected void notifyListeners(final Future future) { - final List>> copy = - new ArrayList>>(); + final List>> copy; synchronized(this) { - copy.addAll(listeners); + if (listeners.isEmpty()) { + copy = null; + } + else { + copy = new ArrayList>>(listeners); + } listeners = new ArrayList>>(); } - for (GenericCompletionListener> listener - : copy) { - notifyListener(executor(), future, listener); + if (copy != null) { + for (GenericCompletionListener> listener + : copy) { + notifyListener(executor(), future, listener); + } } }