kingxip 2009-07-02 11:13
浏览 252
已采纳

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]

  • 写回答

4条回答 默认 最新

  • layer555 2009-07-02 11:46
    关注

    如果有错误就抛出RuntimeException,但是实际中却发现,运行错误的时候tomcat也自动挂掉了。 ?莫非你没有捕捉住自己抛的异常?能不能把问题描述的更清楚一点?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料