title: How to solve java.net.SocketException: Software caused connection abort: socket write error exception
body: <p>I have this error<br>
   SEVERE: <code>SEVERE: Servlet.service() for servlet [jsp] in context with path [/firstjsp] threw exception [ClientAbortException:  java.net.SocketException: Software caused connection abort: socket write error] with root cause</code>
  when I run my application sometimes .</p>
  
  <p>The error messages are</p>
  
  <pre><code>java.net.SocketException: Software caused connection abort: socket write error
  at java.net.SocketOutputStream.socketWrite0(Native Method)
  at java.net.SocketOutputStream.socketWrite(Unknown Source)
  at java.net.SocketOutputStream.write(Unknown Source)
  at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:216)
  at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:460)
  at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:368)
  at org.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:241)
  at org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:119)
  at org.apache.coyote.http11.AbstractOutputBuffer.doWrite(AbstractOutputBuffer.java:192)
  at org.apache.coyote.Response.doWrite(Response.java:533)
  at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:373)
  at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:373)
  at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:403)
  at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:391)
  at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:91)
  at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:84)
  at ChartDirector.GetSessionImage.a(SourceFile:90)
  at ChartDirector.WebChartViewer.streamChart(SourceFile:301)
  at org.apache.jsp.AutomaticAlarm_jsp._jspService(AutomaticAlarm_jsp.java:157)
  at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
  at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
  at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>My java code is:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> public Connection getConnection() {
  
  
     String connectionUrl = "jdbc:sqlserver://localhost:49184;databaseName=Alarm;user=sa;password=Controls@#$%";
  
  
     try {
       Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
       con = DriverManager.getConnection(connectionUrl);
     } catch (Exception e) {
       System.out.println(" \nException in getConnection() " + e);
     }
     return con;
  
   }
  
   public void closeConnection(Statement stmt, ResultSet rs, Connection con) {
     try {
       if (stmt != null) {
         stmt.close();
       }
       if (rs != null) {
         rs.close();
       }
       if (con != null) {
         con.close();
       }
  
     } catch (Exception e) {
       System.out.println("\nexception in closeConnection( Statement stmt, ResultSet rs, Connection con)  " + e);
     }
  
   }
     
  
   public int get_Count1()
  
   {
  
     {
  
  
  
       try {
         con = getConnection();
  
         stmt = con.createStatement();
  
         String sql = " SELECT system_name, COUNT(distinct arrival_time) AS c FROM i2alarmlog WHERE Ack_status = 0 AND Direction='CAME' AND arrival_time between '2014-01-22 17:56:41.000' and '2014-01-24 17:56:41.000' and system_name in('I2-tciu database','i2-vcs logging','Indus1 Vacuum','Indus2 TCIU','Indus2 Vacuum','Septum_SIP2','TL3 Vacuum') GROUP BY system_name UNION ALL select 'TotalSum' as TotalSum,sum(s.c) as TotalValue from (SELECT system_name, COUNT(distinct arrival_time) AS c FROM i2alarmlog WHERE Ack_status = 0 AND Direction='CAME' and arrival_time between '2014-01-22 17:56:41.000' and '2014-01-24 17:56:41.000' AND system_name in('I2-tciu database','i2-vcs logging','Indus1 Vacuum','Indus2 TCIU','Indus2 Vacuum','Septum_SIP2','TL3 Vacuum') GROUP BY system_name ) s";
  
  
         stmt.executeQuery(sql);
         rs = stmt.getResultSet();
  
  
  
         while (rs.next()) {
           t1 = (rs.getInt(2));
  
  
         }
  
       } catch (Exception e) {
         System.out.println("\nException " + e);
  
       } finally {
         closeConnection(stmt, rs, con);
       }
  
     }
  
  
  
     System.out.println(t1);
  
     return t1;
  
   }</code></pre>
  </div>
  </div>
  </p>
  
  <p>How to resolve it.
  I have used Jsp for display.I have used chartdirector for displaying charts as:-</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;% @page import = "ChartDirector.*" %&gt;
    &lt;%
    // The data for the line chart
  
    double[] data1 = ab.total();
  
  // The labels for the line chart
  String[] labels = {
    "VACUUM", "RSS", "MPS", "RF", "BLFE", "ORBIT", "LCW", "TCS", "INTERLOCK", "BDS", "MSIS", "MICROTON", "POWER CONDITIONER", "DATABASE"
  };
  
  XYChart c = new XYChart(1000, 650);
  c.setPlotArea(90, 60, 750, 430);
  
  c.xAxis().setLabels(labels);
  c.xAxis().setTitle("System_Name", "Arial Bold", 12);
  c.xAxis().setLabelStyle("Arial Bold", 10).setFontAngle(45);
  
  c.addBarLayer3(data1).setBorderColor(Chart.Transparent, Chart.softLighting(Chart.Left));
  
  BarLayer layer = c.addBarLayer2(Chart.Stack, 10);
  layer.setAggregateLabelStyle();
  layer.addDataSet(data1, 10, "Arial Bold Italic");
  layer.setBorderColor(Chart.Transparent, Chart.softLighting(Chart.Top));
  
  c.xAxis().setColors(Chart.Transparent);
  c.yAxis().setColors(Chart.Transparent);
  
  
  c.yAxis().setTitle("Alarm_Count", "Arial Bold", 12);
  
  c.yAxis().setLabelStyle("Arial Bold", 10);
  c.yAxis().setLinearScale(0.0, ab.max_Count());
  c.yAxis().setLabelStep(2);
  c.yAxis().setMargin(7);
  c.xAxis().setWidth(2);
  c.yAxis().setWidth(2);
  
  
  try {
    // stream the chart to the browser and terminate immediately
    out.clear();
    if (WebChartViewer.streamChart(response, c.makeChart2(Chart.PNG)))
      return;
  } catch (IllegalStateException e) {
    // Some very old servers may not support streaming. So we are forced to redirect
    // to the browser to use the traditional method.
    response.sendRedirect(response.encodeRedirectURL("getchart.jsp?" +
      c.makeSession(request, "chart")));
    return;
  }
  
  
  %&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Moreover,the chart is updated randomly.</p>