jfclere 02/05/09 14:54:04
Modified: daemon/src/samples ServiceDaemon.java
Added: daemon/src/samples ServiceDaemonReadThread.java
Log:
Add reading stdout/stderr on the created processes (otherwise they hang).
Revision Changes Path
1.3 +16 -2 jakarta-commons-sandbox/daemon/src/samples/ServiceDaemon.java
Index: ServiceDaemon.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/samples/ServiceDaemon.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ServiceDaemon.java 25 Mar 2002 22:37:47 -0000 1.2
+++ ServiceDaemon.java 9 May 2002 21:54:03 -0000 1.3
@@ -55,7 +55,7 @@
* *
* ========================================================================= */
-/* @version $Id: ServiceDaemon.java,v 1.2 2002/03/25 22:37:47 jfclere Exp $ */
+/* @version $Id: ServiceDaemon.java,v 1.3 2002/05/09 21:54:03 jfclere Exp $ */
import java.io.*;
import java.net.*;
@@ -74,6 +74,8 @@
private ExtendedProperties prop = null;
private Process proc[] = null;
+ private ServiceDaemonReadThread readout[] = null;
+ private ServiceDaemonReadThread readerr[] = null;
public ServiceDaemon() {
super();
@@ -107,8 +109,13 @@
}
System.err.println("ServiceDaemon: init for " + i + " processes");
proc = new Process[i];
- for (i=0;i<proc.length;i++)
+ readout = new ServiceDaemonReadThread[i];
+ readerr = new ServiceDaemonReadThread[i];
+ for (i=0;i<proc.length;i++) {
proc[i] = null;
+ readout[i] = null;
+ readerr[i] = null;
+ }
System.err.println("ServiceDaemon: init done ");
@@ -128,6 +135,13 @@
} catch(Exception ex) {
System.err.println("Exception: " + ex);
}
+ /* Start threads to read from Error and Out streams */
+ readerr[i] =
+ new ServiceDaemonReadThread(proc[i].getErrorStream());
+ readout[i] =
+ new ServiceDaemonReadThread(proc[i].getInputStream());
+ readerr[i].start();
+ readout[i].start();
i++;
}
}
1.1
jakarta-commons-sandbox/daemon/src/samples/ServiceDaemonReadThread.java
Index: ServiceDaemonReadThread.java
===================================================================
/* ========================================================================= *
* *
* The Apache Software License, Version 1.1 *
* *
* Copyright (c) 1999-2001 The Apache Software Foundation. *
* All rights reserved. *
* *
* ========================================================================= *
* *
* Redistribution and use in source and binary forms, with or without modi- *
* fication, are permitted provided that the following conditions are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice *
* notice, this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. The end-user documentation included with the redistribution, if any, *
* must include the following acknowlegement: *
* *
* "This product includes software developed by the Apache Software *
* Foundation <http://www.apache.org/>." *
* *
* Alternately, this acknowlegement may appear in the software itself, if *
* and wherever such third-party acknowlegements normally appear. *
* *
* 4. The names "The Jakarta Project", "WebApp", and "Apache Software *
* Foundation" must not be used to endorse or promote products derived *
* from this software without prior written permission. For written *
* permission, please contact <[EMAIL PROTECTED]>. *
* *
* 5. Products derived from this software may not be called "Apache" nor may *
* "Apache" appear in their names without prior written permission of the *
* Apache Software Foundation. *
* *
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY *
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY *
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS *
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, *
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= *
* *
* This software consists of voluntary contributions made by many indivi- *
* duals on behalf of the Apache Software Foundation. For more information *
* on the Apache Software Foundation, please see <http://www.apache.org/>. *
* *
* ========================================================================= */
/* @version $Id: ServiceDaemonReadThread.java,v 1.1 2002/05/09 21:54:03 jfclere Exp
$ */
import java.io.InputStream;
import java.io.IOException;
import java.lang.Thread;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class ServiceDaemonReadThread extends Thread {
private BufferedReader in;
ServiceDaemonReadThread(InputStream in) {
this.in = new BufferedReader(new InputStreamReader(in));
}
public void run() {
String buff;
for (;;) {
try {
buff = in.readLine();
if (buff == null) break;
System.err.print(in.readLine());
} catch (IOException ex) {
break; // Exit thread.
}
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>