0

我的程序递归调用 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(); 
        }
    }

它看起来像是完整程序的挂起;甚至超时(240000 毫秒)也不匹配。GC 日志似乎有点中断:

258.070: [全 GC [PSYoungGen: 13456K->7362K(85120K)] [PSOldGen: 59271K->60735K(81728K)] 72727K->68098K(166848K) [PSPermGen: 16282K->16282K(304090K), [PSPermGen: 16282K->16282K(304090K),时间:用户=0.31 系统=0.00,实际=0.31 秒] 264.208:[GC [PSYoungGen:65466K->8773K(92224K)] 126202K->69581K(173952K),0.0528360 秒] [时间:用户=0.10 系统=0.00,真实=0.05 秒] 265.445: [GC [PSYoungGen: 81774K->9133K(92096K)] 142582K->70061K(173824K), 0.0205430 秒] [时间: 用户=0.03 系统=0.00, 真实=0.02 秒] 266.916: [PSYoungGen: 82515K->9698K(100096K)] 143443K->70658K(181824K), 0.0189050 secs] [Times: user=0.04 sys=0.00, real=0.02 secs] 267.817: [GC [PSYoungGen: 923011K->KK6(10011K->143KK6) )] 153271K->70986K(182208K), 0.0210400 秒] [时间: 用户=0.03 系统=0.01, 实际=0.02 秒] 274.208: [GC [PSYoungGen: 84072K->672K(112256K)] 153622K->71297K(193984K),0.0029610 秒] [时间:用户=0.00 系统=0.00,实际=0.00 秒] 275.769:[GC [PSYoungGen:94880K->500K(11025832K)]73K216 (194560K), 0.0022440 秒]

uvscan 命令在程序启动后 277.609 秒被调用。

谁能建议如何获得挂起的原因?

在此先感谢,乌尔里希

4

0 回答 0