2013-11-02 86 views
0

我正在創建一個類,用於通過實現WatchService的類的實現來創建一個用於監視(用於更改)給定的指令列表的類。Java守護進程處理程序自動終止

,並通過主開始像這樣:

public static void main(String[] args) throws IOException { 
    ClassHandler CH= new ClassHandler(); 
} 

我的問題是,啓動時,它自動終止。可能是因爲Java GC找不到對它的引用?以前沒有這個問題,我能做些什麼來保持它的活躍?

編輯:謝謝您的回覆。當我嘗試這個時,它仍然會立即終止。

Thank you for your reply. Something like this? 

'public static void main(String[] args) throws IOException { 
    Runnable runnable = new Runnable(){ 
     public void run(){ 
      try { 
       new ClassHandler(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 
    }; 
    Thread thread = new Thread(runnable); 
    thread.setDaemon(true); //t.setDaemon(true); 
    thread.start(); 
}' 

然而,這仍然立即終止。

編輯編輯:

沒關係,發現了錯誤。我忘了「激活」watchservice,什麼都不做!它現在有效。不過謝謝你的幫助!

回答