凤凰求蛊
123456789101112131415161718192021222324class Singleton { private static Singleton s; public String str = "你好"; public String getStr(String tName) throws Exception { synchronized (Singleton.class) { //获取资源,保证多线程下不会导致线程冲突 System.out.println(tName + "进入"); Thread.sleep(1000); System.out.println(tName + "结束"); } return str; } private Singleton() { System.out.println("A Singleton Model example"); } public static Singleton getSigleton() { if (s == null) s = new Singleton(); return s; }}