Java进程一夜之间结束

时间:2013-12-05 09:58:09

标签: java

我有我编写的jar文件,用于搜索特定进程并将其写入日志文件。它似乎在白天运行正常,但是在晚上11点到凌晨1点之间,它在我运行它的所有3台机器上停止了(并非所有机器都在同一时间)。

它由一个计划任务启动,该任务每天早上6点调用以下.bat文件。

@echo off
taskkill /IM javaw.exe /F

start javaw -jar -Xms1024m -Xmx1024m E:\tools\Process_monitor\process_mon.jar
Console.exe E:\tools\Process_monitor\logs\console.log

由于1024m没有足够的内存,它是否可能停止,或者它是否是我没有捕获的其他异常?

非常感谢任何其他提示。

public class Main {
  public static void main(String[] args){
    if (args.length == 0){
      System.out.println("Proper usage is: process_mon.jar process_name log_file");
      System.exit(0);
    }
    String process = args[0];
    String logFile = args[1];
    String line;

    // Delete old log file
    File file = new File(logFile);
    file.delete();

    // Create logger
    Logger logger = Logger.getLogger("Log");
    FileHandler fh;

    try {
      fh = new FileHandler(logFile);
      logger.addHandler(fh);
      SimpleFormatter formatter = new SimpleFormatter();
      fh.setFormatter(formatter);
    } catch (IOException e) {
      e.printStackTrace();
    }

    // Check for process 
    try {
      while (true){
        Thread.sleep(5000);
        Process proc = null;
        proc = Runtime.getRuntime().exec("cmd /c tasklist /FI \"IMAGENAME eq " + process + "\"");
        BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
        OutputStreamWriter oStream = new OutputStreamWriter(proc.getOutputStream());
        oStream.write("process where name=" + process);
        oStream.flush();
        oStream.close();
        // Read output of tasklist and write to logfile

        while ((line = input.readLine()) != null){
          logger.info(line);
          Thread.sleep(1800);
        }
        //input.close();
      }
    } catch (
      IOException ioe) {
        ioe.printStackTrace();
      } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } 
    }
  }

0 个答案:

没有答案