KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > ProcessMonitor


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc;
5
6 /**
7  * This is for monitoring a process where something else is draining the output and
8  * error streams, such as a ProcessWaiter or a ProcessOutputView.
9  */

10
11 public class ProcessMonitor extends Thread JavaDoc {
12   private Process JavaDoc m_process;
13   private ProcessTerminationListener m_terminationListener;
14   
15   public ProcessMonitor(Process JavaDoc process,
16                         ProcessTerminationListener terminationListener)
17   {
18     super();
19
20     m_process = process;
21     m_terminationListener = terminationListener;
22     
23     start();
24   }
25
26   public void run() {
27     while(true) {
28       try {
29         m_process.waitFor();
30         m_terminationListener.processTerminated(m_process.exitValue());
31         return;
32       } catch(InterruptedException JavaDoc ie) {/**/}
33     }
34   }
35 }
36
Popular Tags