* Eagerly way rely on JVM, but bad for multi-thread
private static Chimera uniqueInstance = new Chimera(3); private Chimera(int level) {super(level);} public static Chimera getInstance() { return uniqueInstance; }
* Double lock Chimera reduce synchronized, but suitable for Java 5 above
/* private and static for prevent public calling and allocate specific memory location
volatile means the working memory of each thread is not used, and access, reading and writing are always done from the main memory. */ private volatile static Chimera uniqueInstance; private Chimera(int level) {super(level);} public static Chimera getInstance() { // if not instantized, into synchronized block if (uniqueInstance == null){ synchronized (Chimera.class){ // use synchronized good for multithread, but lower performance // check again in synchronized block if(uniqueInstance == null) uniqueInstance = new Chimera(3); } } return uniqueInstance; }