#108 Consistent package naming throughout the examples

This commit is contained in:
Ilkka Seppala
2015-07-24 11:32:22 +03:00
parent af92d8dde5
commit 3d488ec15a
128 changed files with 963 additions and 873 deletions

View File

@ -0,0 +1,34 @@
package com.iluwatar.lazy.loading;
import java.util.function.Supplier;
/**
*
* This lazy loader is thread safe and more efficient than HolderThreadSafe.
* It utilizes Java 8 functional interface Supplier<T> as Heavy factory.
*
*/
public class Java8Holder {
private Supplier<Heavy> heavy = () -> createAndCacheHeavy();
public Java8Holder() {
System.out.println("Java8Holder created");
}
public Heavy getHeavy() {
return heavy.get();
}
private synchronized Heavy createAndCacheHeavy() {
class HeavyFactory implements Supplier<Heavy> {
private final Heavy heavyInstance = new Heavy();
@Override
public Heavy get() { return heavyInstance; }
}
if (!HeavyFactory.class.isInstance(heavy)) {
heavy = new HeavyFactory();
}
return heavy.get();
}
}