Java.io.IOException:Stream closed
multiple threads index the same input stream, when a thread has finished executing, the InputStream is closed; the thread that reads information from the stream is thrown java.io.IOException: Stream closed exception.
finally find out the origin of this anomaly, originally two pages call a JSP, the built-in object in this JSP
The exception that occurs when an out executes out.close (), that is, when a thread (corresponding to a JSP) finishes executing the
, the stream is closed, and another JSP that is reading the information from this stream is thrown
java.io.IOException: Stream closed exception.
Modify the previous code:
Public object senddata (STRING JSONSTR) {// 1. Specifies the WebService namespace and method name of the call Soapobject rpc = new soapobject (Namespace, methodname);// 2. sets the parameter value of the calling method, which is optional, If the method has no parameters, you can omit this step rpc.addproperty ("arg000", jsonstr);// 3. generate the SOAP request information that calls the WebService method. Soapserializationenvelope envelope = new soapserializationenvelope (SOAPENVELOPE.VER11); envelope.encodingstyle = "UTF-8";envelope.bodyout = rpc;// Envelope.setoutputsoapobject (RPC);// 4.// creates Httptransportse objects. The constructor of the Httptransportse class allows you to specify the Urlhttptransportse ht = new httptransportse of the WebService WSDL document ( URL);ht.debug = true;object detail1 = null;try {// 5. Use the call method to invoke the WebService method Ht.call (Null, envelope);// detail = (soapobject) Envelope.getresponse ();// 6. uses the GetResponse method to obtain the return result of the WebService method detail1 = Envelope.getresponse ();} catch (ioexception e) {// todo auto-generated catch blocke.printstacktrace ();} catch (xmlpullparserexception e) {// TODO Auto-generated catch Blocke.printstacktrace ();} Return detail1;}
Modified code:
Public object senddata (STRING JSONSTR) {// 1. Specifies the WebService namespace and method name of the call Soapobject rpc = new soapobject (Namespace, methodname);// 2. sets the parameter value of the calling method, which is optional, If the method has no parameters, you can omit this step rpc.addproperty ("arg000", jsonstr);// 3. generate the SOAP request information that calls the WebService method. Soapserializationenvelope envelope = new soapserializationenvelope (SOAPENVELOPE.VER11); envelope.encodingstyle = "UTF-8";envelope.bodyout = rpc;// Envelope.setoutputsoapobject (RPC);// 4.// creates Httptransportse objects. The constructor of the Httptransportse class allows you to specify the Urlhttptransportse ht = new httptransportse of the WebService WSDL document ( URL);ht.debug = true;object detail1 = null;try {// 5. Use the call method to invoke the WebService method Ht.call (Null, envelope);// detail = (soapobject) Envelope.getresponse ();// 6. uses the GetResponse method to obtain the return result of the WebService method detail1 = Envelope.getresponse ();} catch (ioexception e) {// todo auto-generated catch blocke.printstacktrace (); System.out.println (New java.util.date () + "Ioexception, resend the data"); try {// 5. use the call method to invoke the WebService method Ht.call (Null, envelope);// detail = ( Soapobject) envelope.getresponse ();// 6. Use the GetResponse method to obtain the return result of the WebService method detail1 = Envelope.getresponse ();} catch (IOEXCEPTION E1) {// TODO Auto-generated catch block E1.printstacktrace ();} catch (XMLPULLPARSEREXCEPTION E1) {// TODO Auto-generated catch Block E1.printstacktrace ();}} catch (xmlpullparserexception e) {// TODO Auto-generated catch Blocke.printstacktrace ();} Return detail1;}
This article is from the "CARLWU" blog, make sure to keep this source http://carlwu.blog.51cto.com/2329717/1617275
Causes and treatment of java.io.IOException:Stream closed anomalies