Runnable (final long ts) { return () -> { final List<T> list; synchronized (myFlushLock) { myTs = ts; myPendingFlush = false; if (myBuffer.isEmpty()) return; list = myBuffer; myBuffer = new ArrayList<>(mySize); } myConsumer.consume(list); }; }