Skip to content

Instantly share code, notes, and snippets.

@javarouka
Created December 14, 2017 02:38
Show Gist options
  • Save javarouka/26c112bc30bfb537cea691ef1f3c73cf to your computer and use it in GitHub Desktop.
Save javarouka/26c112bc30bfb537cea691ef1f3c73cf to your computer and use it in GitHub Desktop.
Singleton - Layholder
package io.javarouka.gist.pattern;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class SingletonLayholder {
static {
log.debug("SingletonLayholder initialized");
}
private SingletonLayholder() {
log.debug("Created! " + this.getClass().getSimpleName());
}
public static void foke() {
log.debug("fork!");
}
public static SingletonLayholder getInstance() {
return LazyHolder.INSTANCE;
}
private static class LazyHolder {
static {
log.debug("SingletonLayholder.LazyHolder initialized");
}
private static final SingletonTestLayholder INSTANCE = new SingletonTestLayholder();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment