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...."); 
} 

답변

1

DefaultFileMonitor 작품은, 가상 기계 모니터 스레드가 실행되는 경우에도 종료한다. 해결 방법은 무한 루프 또는 사용자가 제어 할 수있는 다른 종류의 루프가있는 데몬이 아닌 스레드를 사용하는 것입니다.