package com.cavaness.quartzbook.chapter3;public class Test {private static Test instance = null;public static synchronized Test getInstance() {// 这个方法比上面有所改进,不用每次都进行生成对象,只是第一次 // 使用时生成实例,提高了效率!if (instance == null) {instance = new Test();}return instance;}public void method() {System.out.println("The method of Test!");}
}class Test2 {public static void main(String[] args) {Test.getInstance().method();}
}
详细解决方案
单例2
热度:80 发布时间:2024-01-17 03:12:51.0
相关解决方案