ProcessTerminationMonitor.java

  1. // @formatter:off
  2.  /*******************************************************************************
  3.  *
  4.  * This file is part of JMad.
  5.  *
  6.  * Copyright (c) 2008-2011, CERN. All rights reserved.
  7.  *
  8.  * Licensed under the Apache License, Version 2.0 (the "License");
  9.  * you may not use this file except in compliance with the License.
  10.  * You may obtain a copy of the License at
  11.  *
  12.  *     http://www.apache.org/licenses/LICENSE-2.0
  13.  *
  14.  * Unless required by applicable law or agreed to in writing, software
  15.  * distributed under the License is distributed on an "AS IS" BASIS,
  16.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17.  * See the License for the specific language governing permissions and
  18.  * limitations under the License.
  19.  *
  20.  ******************************************************************************/
  21. // @formatter:on

  22. package cern.accsoft.steering.jmad.util;

  23. import org.slf4j.Logger;
  24. import org.slf4j.LoggerFactory;

  25. public class ProcessTerminationMonitor extends Thread {
  26.     private static final Logger LOGGER = LoggerFactory.getLogger(ProcessTerminationMonitor.class);
  27.     private static final long POLL_INTERVALL = 10;

  28.     private final Process process;

  29.     public ProcessTerminationMonitor(Process process) {
  30.         this.process = process;
  31.     }

  32.     @Override
  33.     public void run() {
  34.         while (ProcTools.isRunning(process)) {
  35.             try {
  36.                 sleep(POLL_INTERVALL);
  37.             } catch (InterruptedException e) {
  38.                 LOGGER.warn("Waiting for terminating process '" + process.toString() + "' was interrupted.", e);
  39.             }
  40.         }
  41.     }

  42. }