Web Service具有随机的ClosedByInterruptException

时间:2013-09-02 07:48:08

标签: java oracle web-services exception glassfish

我听说有一个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)

随机时间,我会在日志中看到它。 问题是当我的Web服务应该返回它的值时,就会发生这种情况。我有以下代码:

   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有正确的数据,差别只有几毫秒,所以proccess似乎工作正常。

我已经读过ClosedByInterruptException可能是由线程中断引起的,所以我检查了我的管理控制台(我正在使用Glassfish)它似乎还可以,我已经允许200个线程,超时@ 900秒。

此Web服务大部分时间都可以使用,有时会这样做。 web服务本身正在调用Oracle 11g数据库中的一个过程,我想也许它与数据库的一些瓶颈有关,但是它不会显示带有正确数据的println我猜,也就是程序做了它所要求的发生此错误时。

所以我的问题是,这个错误是什么,或者我怎么能抓住它?我试着抓住它,但那不起作用。

1 个答案:

答案 0 :(得分:0)

从堆栈跟踪判断,在编写响应时会发生异常。这表明真正的原因是网络问题或没有阅读响应的客户端。

在任何一种情况下,最好的办法是允许异常传播,或者捕获它并放弃处理请求。几乎没有机会做任何允许服务器将响应发送给客户端的事情。