我听说有一个 Java FileChannel 错误,但我有一个 web 服务。
我得到以下异常:
java.nio.channels.ClosedByInterruptException
at java.nio.channels.spi.AbstractInterruptibleChannel.end
(AbstractInterruptibleChannel.java:202)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:473)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.flushByteBuffer
(TCPNIOTransport.java:1252)
at org.glassfish.grizzly.nio.transport.TCPNIOAsyncQueueWriter.write0
(TCPNIOAsyncQueueWriter.java:107)
at org.glassfish.grizzly.nio.AbstractNIOAsyncQueueWriter.write(AbstractNIOAsyncQueueWriter.java:296)
at org.glassfish.grizzly.nio.AbstractNIOAsyncQueueWriter.write(AbstractNIOAsyncQueueWriter.java:203)
at org.glassfish.grizzly.nio.AbstractNIOAsyncQueueWriter.write(AbstractNIOAsyncQueueWriter.java:73)
at org.glassfish.grizzly.nio.transport.TCPNIOTransportFilter.handleWrite(TCPNIOTransportFilter.java:128)
at org.glassfish.grizzly.filterchain.TransportFilter.handleWrite(TransportFilter.java:191)
at org.glassfish.grizzly.filterchain.ExecutorResolver$8.execute(ExecutorResolver.java:111)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.filterchain.FilterChainContext.write(FilterChainContext.java:853)
at org.glassfish.grizzly.filterchain.FilterChainContext.write(FilterChainContext.java:822)
at org.glassfish.grizzly.http.io.OutputBuffer.flushBuffer(OutputBuffer.java:1011)
at org.glassfish.grizzly.http.io.OutputBuffer.flushBinaryBuffers(OutputBuffer.java:996)
at org.glassfish.grizzly.http.io.OutputBuffer.flushAllBuffers(OutputBuffer.java:967)
at org.glassfish.grizzly.http.io.OutputBuffer.flush(OutputBuffer.java:732)
at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:291)
at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:275)
at org.apache.catalina.connector.CoyoteOutputStream.flush(CoyoteOutputStream.java:175)
at com.ctc.wstx.io.UTF8Writer.flush(UTF8Writer.java:103)
at com.ctc.wstx.sw.BufferingXmlWriter.flush(BufferingXmlWriter.java:225)
at com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:261)
at com.sun.xml.ws.util.xml.XMLStreamWriterFilter.flush(XMLStreamWriterFilter.java:71)
at com.sun.xml.ws.streaming.XMLStreamWriterUtil.getOutputStream(XMLStreamWriterUtil.java:103)
at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:392)
有时,我会在我的日志中看到它。事情是当我的网络服务应该返回它的值时,这种情况就会发生。我有以下代码:
cs = con.prepareCall (" { call charge_subscriber (?,?,?,?,?,?)} ");
cs.registerOutParameter(4, java.sql.Types.INTEGER);
cs.registerOutParameter(5, java.sql.Types.VARCHAR);
cs.registerOutParameter(6, java.sql.Types.NUMERIC);
cs.setInt(1, anum);
cs.setInt(2, product_id);
cs.setString(3, identifier);
cs.execute();
resultCode = cs.getInt(4);
resultMessage = cs.getString(5);
transNo = cs.getLong(6);
System.out.println("\n ANUM : "+anum+
"\n Product ID : "+product_id+
"\n Identifier : "+identifier+
"\n resultCode : "+resultCode+
"\n resultMessage : "+resultMessage+
"\n transNo : "+transNo);
return new ApiResponse(resultCode,resultMessage,transNo);
} catch(Exception e){
System.out.println("Exception while charging : "+e.getMessage());
}
finally {
if(!con.isClosed())
con.close();
con = null;
if(cs != null)
cs.close();
cs = null;
return new ApiResponse(resultCode,resultMessage,transNo);
}
在异常的正上方,我看到 println 的数据正确,相差几毫秒,所以进程似乎工作正常。
我已经读过这ClosedByInterruptException
可能是由线程中断引起的,所以我检查了我的管理控制台(我正在使用 Glassfish),它似乎也没问题,我允许 200 个线程,超时@ 900 秒。
此 Web 服务大部分时间都在工作,有时它会这样做。Web服务本身正在调用Oracle 11g数据库中的一个过程,我认为这可能与数据库的某些瓶颈有关,但是我猜它不会显示带有正确数据的println,而且该过程也做了它应该做的事情发生此错误时。
所以我的问题是,这个错误可能是什么,或者我怎么能抓住它?我试图抓住它,但没有奏效。