Package com.wz.thread.delay;
/**
* Lazy Load/Lazy mode single case design mode
* Using the DCL double check lock mechanism, DCL is the most multi-threaded combination of single-case mode using which solution
* @author Administrator
*
*/
public class MyObject {
Private volatile static MyObject MyObject;
Private MyObject () {}
public static MyObject getinstance () {
try {
if (myObject! = null) {
}else {
Thread.Sleep (3000);
Synchronized (Myobject.class) {
if (MyObject = = null) {
MyObject = new MyObject ();
}
}
}
} catch (Exception e) {
E.printstacktrace ();
}
return myObject;
}
}
Package com.wz.thread.delay;
public class MyThread extends Thread {
@Override
public void Run () {
Super.run ();
System.out.println (Myobject.getinstance (). Hashcode ());
}
}
Package com.wz.thread.delay;
/**
* The Hascode value of the output is the same, indicating that the same object
* @author Administrator
*
*/
public class Run {
public static void Main (string[] args) {
MyThread T1 = new MyThread ();
MyThread t2 = new MyThread ();
MyThread t3 = new MyThread ();
T1.start ();
T2.start ();
T3.start ();
}
}
Lazy loading of multithreaded singleton mode (lazy mode)