java.lang.Process在递归调用时挂起

时间:2013-06-27 16:28:28

标签: mcafee

我的程序递归调用McAfee OnDemad Virusscanner来获取特定路径。在一个循环中,我用几个文件填充路径,扫描它,删除文件,填充它等等。 过了一会儿,程序突然挂起,我不知道原因。

        Calendar cl = Calendar.getInstance();
        String cmd="uvscan -v /var/tmp/McAfee/scanFiles/"
        try {   
        long start=cl.getTimeInMillis();
        process = Runtime.getRuntime().exec(cmd, null);
        Worker worker = new Worker(process);
        worker.start(); 
        try {
            LOGGER.debug("Virusscan timeout set to {}ms", timeout);
            worker.join(timeout);
            if (worker.exit != null)
                workerRC=worker.exit;
            else {
                cl = Calendar.getInstance();
                long waitTime=cl.getTimeInMillis()-start;
                throw new TimeoutException("Virusscan timeout after " + waitTime + "ms"); 
            }
            //      else
            //          throw new TimeoutException();
        } catch(InterruptedException ex) {
            worker.interrupt();
            Thread.currentThread().interrupt();
            cl = Calendar.getInstance();
            long waitTime=cl.getTimeInMillis()-start;
            throw new TimeoutException("Virusscan timeout after " + waitTime + "ms"); 
        } 

        File scanLog = new File(ConfigReader.getScanLog());
        if (!ConfigReader.mustKeepScanLog()) scanLog.deleteOnExit();
        LOGGER.debug("ScanLog is: " + scanLog.getPath() + " - RC=" + workerRC);
        BufferedWriter bw = new BufferedWriter(new FileWriter(scanLog));
        BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
        // read the output from the command             
        while ((buffer = stdInput.readLine()) != null) {
            inspectScanlog(buffer, workerRC);
            bw.write(buffer+"\n");
            LOGGER.debug("Scan STDOUT: " + buffer);
        }
        BufferedReader stdErr = new BufferedReader(new InputStreamReader(process.getErrorStream()));
        while ((buffer = stdErr.readLine()) != null) {
            LOGGER.debug("Scan STDERR: " + buffer);
        }

        bw.close();

        cl = Calendar.getInstance();
        long waitTime=cl.getTimeInMillis()-start;
        LOGGER.info("Virusscan took " + waitTime + "ms");
        if (workerRC != 0){
            int cc=12;
            ConfigReader.setMaxCC(cc);
            LOGGER.error("RC={} - Virusscan ended with error. CMD=",cc, cmd);
            if (workerRC==13) {
                LOGGER.error("RC={} - The scanner found one or more viruses or hostile objects - such as a Trojan-horse program, joke program, or test file.", cc);
            }
        }
    }
    catch (Exception e) {
        int cc=12;
        ConfigReader.setMaxCC(cc);
        LOGGER.error("RC={} - {}",cc, e.getMessage());
        e.printStackTrace();
    } finally {
        if (process!=null) {
            process.destroy(); 
        }
    }

它看起来像是整个程序的悬念;甚至超时(240000ms)也不匹配。 GC-log似乎有点中断:

  

258.070:[Full GC [PSYoungGen:13456K-> 7362K(85120K)] [PSOldGen:59271K-> 60735K(81728K)] 72727K-> 68098K(166848K)[PSPermGen:16282K-> 16282K(30400K) )],0.3019290秒] [时间:用户= 0.31 sys = 0.00,实际= 0.31秒]   264.208:[GC [PSYoungGen:65466K-> 8773K(92224K)] 126202K-> 69581K(173952K),0.0528360秒] [时间:用户= 0.10 sys = 0.00,实际= 0.05秒]   265.445:[GC [PSYoungGen:81774K-> 9133K(92096K)] 142582K-> 70061K(173824K),0.0205430秒] [时间:用户= 0.03 sys = 0.00,实际= 0.02秒]   266.916:[GC [PSYoungGen:82515K-> 9698K(100096K)] 143443K-> 70658K(181824K),0.0189050秒] [时间:用户= 0.04 sys = 0.00,实际= 0.02秒]   267.817:[GC [PSYoungGen:92311K-> 1436K(100480K)] 153271K-> 70986K(182208K),0.0210400秒] [时间:用户= 0.03 sys = 0.01,实际= 0.02秒]   274.208:[GC [PSYoungGen:84072K-> 672K(112256K)] 153622K-> 71297K(193984K),0.0029610秒] [时间:用户= 0.00 sys = 0.00,实际= 0.00秒]   275.769:[GC [PSYoungGen:94880K-> 500K(112832K)] 165505K-> 71732K(194560K),0.0022440 secs]

uvscan-command在程序启动后被称为277.609秒。

有人可以建议如何解决这个问题吗?

提前致谢, 乌尔里希

0 个答案:

没有答案