Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static <T> T getWithDcl(Supplier<T> supplier, Supplier<T> factory, Object mutex) {
- T object = supplier.get();
- if (object == null) {
- synchronized (mutex) {
- object = supplier.get();
- if (object == null) {
- object = factory.get();
- }
- }
- }
- return object;
- }
- // Usage
- Locks.getWithDcl(() -> pool.poll(), () -> factory.apply(this), pool);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement