我正在创建一个类,用于通过实现一个实现 WatchService 的类来监视(更改)给定的指令列表。
并像这样通过 Main 开始:
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,什么都不做!现在可以了。不过感谢您的帮助!