1
我在維護vfs2的DefaultFileMonitor線程時遇到問題。執行的主線程在監視器對象啓動後才正常終止。我想知道爲什麼這個對象不會被「監視」,而是直接到最後。 (與日誌消息結束「exitting ......」)vfs2 DefaultFileMonitor線程過早終止
public static void main(String[] args) {
try {
Options options = new Options();
options.addOption("b", true, "path to the build file");
options.addOption("d", true, "directory to watch");
CommandLineParser parser = new PosixParser();
CommandLine cmd = parser.parse(options, args);
String dir = cmd.getOptionValue("d");
String buildFile = cmd.getOptionValue("b");
if(dir == null) {
logger.error("No directory specified," +
" use [-d 'name_of_dir'] to specify one");
return;
}
if(buildFile == null) {
logger.error("No build file path specified," +
" use [-b 'path_to_build_file'] to specify one");
return;
}
FileSystemManager fsManager = VFS.getManager();
FileObject listendir = fsManager.resolveFile(dir);
DefaultFileMonitor fm = new DefaultFileMonitor(new CustomFileListener(buildFile));
fm.setRecursive(true);
fm.addFile(listendir);
fm.start();
}catch(Exception e){
logger.error("Exception ", e);
}
logger.info("exitting....");
}