public class Singleton {//定义私有的静态变量 private static Singleton singleton;//私有化构造函数private Singleton(){}//获取实例public static Singleton getInstance(){//同步前判断避免同步的性能损耗if(null==singleton){//预防多线程问题synchronized(Singleton.class){if(null==singleton){singleton=new Singleton();}}}return singleton;}
}
线程池中缓存线程的集合就是个单例