Java tomcat中的非容器线程错误是什么?
在我的Java tomcat中的非容器线程错误是什么?,java,tomcat,log4j,tomcat7,Java,Tomcat,Log4j,Tomcat7,在我的Tomcat7的catalina.out日志中,我得到一个由第三方库引起的错误,该库以以下内容开头: INFO: An error occurred in processing while on a non-container thread. The connection will be closed immediately java.net.SocketException: Broken pipe at java.net.SocketOutputStream.socket
Tomcat7的catalina.out
日志中,我得到一个由第三方库引起的错误,该库以以下内容开头:
INFO: An error occurred in processing while on a non-container thread. The connection will be closed immediately
java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
在非容器线程中发生错误的真正含义是什么
我试图通过从我的应用程序代码生成的新线程中抛出异常来获取类似的日志消息,如下所示:
new Thread(){
@Override
public void run() {
Integer.parseInt("boom");
}
}.start();
但结果是
Exception in thread "Thread-28" java.lang.NumberFormatException: For input string: "boom"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at ...
所以问题是:当我看到上面引用的日志时,这意味着什么?错误发生在非容器线程中意味着什么?我如何重新创建它?第一期:
信息:在非容器线程上处理时出错。
连接将立即关闭
Ans:
OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
bw.write("Lorem ipsum...");
out.close();
OutputStream os = urlConnection.getOutputStream();
OutputStream out = new BufferedOutputStream(os);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
bw.write("Lorem ipsum...");
bw.close(); //This is must. If you miss to close, then "java.net.SocketException: Broken pipe" error comes
out.close();
os.close();
async.Stockticker
线程由于未处理的ISE而崩溃。这就解释了这种行为。该异常仅记录到控制台。它没有登录到Tomcat日志文件中。
这是Tomcat的错误处理错误。这不是最近变化的倒退。它可以用Tomcat 7.0.59再现
它已经固定在中继8.0.x(对于8.0.21以后的版本)
和7.0.x(对于7.0.60以后的版本)
中。因此您可以升级您的tomcat版本。然后将不显示此信息消息
资源链接:
第二期:
java.net.SocketException:管道破裂
解决方案1:
这个问题实际上发生在我们没有关闭像URLConnection这样的连接和关闭各种打开的流时。我想分享一个例子
之前:
OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
bw.write("Lorem ipsum...");
out.close();
OutputStream os = urlConnection.getOutputStream();
OutputStream out = new BufferedOutputStream(os);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
bw.write("Lorem ipsum...");
bw.close(); //This is must. If you miss to close, then "java.net.SocketException: Broken pipe" error comes
out.close();
os.close();
之后:
OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
bw.write("Lorem ipsum...");
out.close();
OutputStream os = urlConnection.getOutputStream();
OutputStream out = new BufferedOutputStream(os);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
bw.write("Lorem ipsum...");
bw.close(); //This is must. If you miss to close, then "java.net.SocketException: Broken pipe" error comes
out.close();
os.close();
解决方案2:
当我们想在应用服务器中加载测试时,有时会发生此错误
生成数据需要很长时间
,负载测试工具不会等待大量数据足够长时间
,然后关闭连接。实际上,内存不足导致应用程序关闭接收套接字或完全退出,具有相同的效果
如果我们向JVM添加额外的内存,那么问题就解决了。
解决方案3:
正如建议的那样
这是由于在另一端已关闭连接时写入连接造成的
因此,您的应用程序协议定义或实现得很差。如果发生这种情况,您的应用程序协议规范或实现有问题,很可能您甚至没有连接
如果服务器端HTTP应用程序出现断管异常,则表示客户端浏览器已退出/转到另一个页面/超时/消失
返回历史记录/任何内容。算了吧
资源链接:
如果您想重现此错误,那么这可能会对您有所帮助
第三期:
线程“thread-28”java.lang.NumberFormatException中的异常:用于
输入字符串:“动臂”
当您试图将字母字符串转换/解析为整数时,会发生此错误。这是正常的java错误NumberFormatException
更新:
正如您想知道的,在哪些情况下Tomcat决定登录
捕获从中抛出的异常时的附加消息
申请书。所以我简单地分享一下
为了清楚地了解“信息:在非容器线程上处理时发生错误。连接将立即关闭java.net.SocketException:break pipe”
,首先我想与您分享,这是与套接字相关的问题。tomcat中有6个SocketEvent。它们是OPEN\u READ、OPEN\u WRITE、STOP、TIMEOUT、DISCONNECT和ERROR
。这些事件发生在每个需要容器进一步处理的套接字上。这些事件通常由套接字实现触发,但也可能由容器触发
套接字事件“错误”:
非容器线程上发生错误,处理需要返回容器进行任何必要的清理。使用该方法的示例包括:
- 由NIO2发出完成处理程序失败的信号
- 由容器在Servlet 3.0异步处理期间发出非容器线程上的I/O错误信号
当发生此错误并且信息消息显示在TOMCAT中时?
这是信息消息出现的代码快照
/**
* Update the current error state to the new error state if the new error
* state is more severe than the current error state.
* @param errorState The error status details
* @param t The error which occurred
*/
protected void setErrorState(ErrorState errorState, Throwable t) {
boolean blockIo = this.errorState.isIoAllowed() && !errorState.isIoAllowed();
this.errorState = this.errorState.getMostSevere(errorState);
if (blockIo && !ContainerThreadMarker.isContainerThread() && isAsync()) {
// The error occurred on a non-container thread during async
// processing which means not all of the necessary clean-up will
// have been completed. Dispatch to a container thread to do the
// clean-up. Need to do it this way to ensure that all the necessary
// clean-up is performed.
if (response.getStatus() < 400) {
response.setStatus(500);
}
getLog().info(sm.getString("abstractProcessor.nonContainerThreadError"), t); // This section gives the INFO message "INFO: An error occurred in processing while on a non-container thread. The connection will be closed immediately"
socketWrapper.processSocket(SocketEvent.ERROR, true);
}
}
在非容器线程中调用ExecuteOnBlockingDispatches(…)方法时,以及它如何与SocketTrapper交互?
当通过在非容器线程中定义读和/或写侦听器来启动非阻塞IO时,将调用此方法。一旦非容器线程完成,就会调用它,以便容器根据需要对onWritePossible()
和/或onDataAvailable()
进行第一次调用
处理调度需要(至少对于APR/native)
套接字已添加到waitingRequests队列。在非容器线程完成触发对该方法的调用时,可能没有发生这种情况因此,SocketWrapper上的编码同步作为启动此非容器线程的容器线程在SocketWrapper上保持锁定。容器线程将在释放SocketTrapper上的锁之前将套接字添加到waitingRequests队列。因此,通过在处理调度之前获得socketWrapper上的锁,我们可以确保已将套接字添加到waitingRequests队列
错误发生在非容器线程中的真正含义是什么
当您使用JSP3.0+异步请求处理时,就会发生这种情况
在异步模式下,客户端请求由调用Servlet的service()
方法的“容器”线程接收。此方法(或子方法之一)