1 /** 2 * 单例 3 */ 4 public class JobSchedulerService { 5 //防止类外部通过new实例化该类 6 private JobSchedulerService() { 7 8 } 9 //使用内部类来维护单例 10 private static class jobSchedulerServiceFactory { 11 private static JobSchedulerService instance=new JobSchedulerService(); 12 } 13 //提供方法供外部获取单例 14 public static JobSchedulerService getInstance() { 15 return jobSchedulerServiceFactory.instance; 16 } 17 }