@Test public void testPopWhenOnTheFlyGenerationNeeded() { FixedSizePreloadCache<String> cache = new FixedSizePreloadCache<>(0, () -> Thread.currentThread().getName()); String actual = cache.pop(); assertEquals(Thread.currentThread().getName(), actual); }
public E pop() { E element; synchronized (stack) { element = stack.isEmpty() ? null : stack.pop(); } if (element == null) { return generator.get(); } new Thread(() -> push(generator.get())).start(); return element; }
FixedSizePreloadCache { public E pop() { E element; synchronized (stack) { element = stack.isEmpty() ? null : stack.pop(); } if (element == null) { return generator.get(); } new Thread(() -> push(generator.get())).start(); return element; } }
FixedSizePreloadCache { public E pop() { E element; synchronized (stack) { element = stack.isEmpty() ? null : stack.pop(); } if (element == null) { return generator.get(); } new Thread(() -> push(generator.get())).start(); return element; } FixedSizePreloadCache(int maxSize, Supplier<E> generator); }
FixedSizePreloadCache { public E pop() { E element; synchronized (stack) { element = stack.isEmpty() ? null : stack.pop(); } if (element == null) { return generator.get(); } new Thread(() -> push(generator.get())).start(); return element; } FixedSizePreloadCache(int maxSize, Supplier<E> generator); E pop(); int size(); }
FixedSizePreloadCache { public E pop() { E element; synchronized (stack) { element = stack.isEmpty() ? null : stack.pop(); } if (element == null) { return generator.get(); } new Thread(() -> push(generator.get())).start(); return element; } FixedSizePreloadCache(int maxSize, Supplier<E> generator); E pop(); int size();  }