effective java中的單例模式創建實例

public class SynWithServer {
	private ScheduledExecutorService scheduler = null;
	private static class SingletonClassInstance 
	{ 
		private static final SynWithServer instance =new SynWithServer(); 
	} 

	public static SynWithServer getInstance() 
	{ 
	     return SingletonClassInstance.instance; 
	} 

	private SynWithServer() { 
		scheduler = Executors.newSingleThreadScheduledExecutor(); 
	} 
	public boolean synchronize(String userId){
		TableSchedule.SynIngFlag =true;
	   	scheduler.schedule(new Runnable() {  
		public void run() {  
	 	// 排程工作  
		}  
	},  30, TimeUnit.SECONDS);
	TableSchedule.SynIngFlag =false;
	return true; 
}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章