Advertisement
Guest User

Untitled

a guest
May 27th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. public static <T> T getWithDcl(Supplier<T> supplier, Supplier<T> factory, Object mutex) {
  2. T object = supplier.get();
  3. if (object == null) {
  4. synchronized (mutex) {
  5. object = supplier.get();
  6. if (object == null) {
  7. object = factory.get();
  8. }
  9. }
  10. }
  11.  
  12. return object;
  13. }
  14.  
  15. // Usage
  16. Locks.getWithDcl(() -> pool.poll(), () -> factory.apply(this), pool);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement