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; } }
时间: 2024-11-09 15:23:14