tomcat自动关闭

做了一个web service 其中有一个类通过Runtime调用一些命令行的命令,另外一个类获取执行结果,也就是读取最后的屏幕输出,如果有错误就抛出RuntimeException,但是实际中却发现,运行错误的时候tomcat也自动挂掉了。

tomcat日志:

2009-7-2 11:06:59 org.apache.catalina.startup.Catalina start
信息: Server startup in 3266 ms

2009-7-2 11:07:03 org.apache.coyote.http11.Http11BaseProtocol pause
信息: Pausing Coyote HTTP/1.1 on http-9000
2009-7-2 11:07:04 org.apache.catalina.core.StandardService stop
信息: Stopping service Catalina
2009-7-2 11:07:04 org.apache.catalina.core.StandardWrapper unload
信息: Waiting for 1 instance(s) to be deallocated
2009-7-2 11:07:05 org.apache.catalina.core.StandardWrapper unload
信息: Waiting for 1 instance(s) to be deallocated
2009-7-2 11:07:06 org.apache.catalina.core.StandardWrapper unload
信息: Waiting for 1 instance(s) to be deallocated
2009-7-2 11:07:07 org.apache.coyote.http11.Http11BaseProtocol destroy
信息: Stopping Coyote HTTP/1.1 on http-9000
2009-7-2 11:07:07 org.apache.catalina.core.AprLifecycleListener lifecycleEvent

信息: Failed shutdown of Apache Portable Runtime

有没有办法解决
[b]问题补充:[/b]
[code="java"]
final class ThreadError extends Thread {
private static Logger LOGGER = Logger.getLogger(ThreadError.class);
/**
* Process
*/
private Process ps;

/**
 * Talend SDI component identifier
 */
private String cid;

/**
 * Class constructor
 * 
 * @param ps
 * @param cid
 */
public ThreadError(Process ps, String cid) {
    this.ps = ps;
    this.cid = cid;
}

/**
 * Run the command.
 */
public void run() {
    try {
        java.io.BufferedReader reader = new java.io.BufferedReader(
                new java.io.InputStreamReader(this.ps.getErrorStream()));
        String line = "";
        try {
            while ((line = reader.readLine()) != null) {
                System.err.println(this.cid + "|ERROR|" + line);
                LOGGER.warn(this.cid + "|ERROR|" + line);
            }
        } finally {
            reader.close();
            if (this.ps.exitValue() != 0) {
                LOGGER
                        .warn(this.cid
                                + "|ERROR|Execution failure, there might be an error in your command. [exit code="
                                + this.ps.exitValue() + "]");

// System.exit(this.ps.exitValue());
throw new RuntimeException(
this.cid
+ "|ERROR|Execution failure, there might be an error in your command. [exit code="
+ this.ps.exitValue() + "]");

            }
        }
    } catch (java.io.IOException ioe) {
        ioe.printStackTrace();
    }
}

}

[/code]
上面就是我代码,这个线程获取错误信息,如果执行错误line不为空,那么就跑出RuntimeException,但是实际中如果执行错误也就是命令有问题的时候,tomcat也直接挂掉了
[b]问题补充:[/b]
[quote]你是另开了一个jvm实例吧,然后那个实例搞出问题了,可能导致系统退出
怀疑你用了System.exit(xxx);[/quote]
没有吧,system.exit 我没用啊
[b]问题补充:[/b]
[quote]ThreadError 这个线程类是由tomcat来启动的话,还是怎么,[/quote]
:D

不是tomcat启动,是我在程序中开始执行命令的时候启动比如:
[code="java"]class App {
ThreadError te=null;
public void run(String cmd) {
.......//run the cmd
te=new ThreadError();
........//other codes
}
}[/code]

查看全部
kingxip
kingxip
2009/07/02 11:13
  • tomcat
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

0个回复