tomcat服务器上得程序,线程启动,dbcp连接池.运行一会就报连接超时

方小波 发布于 2015/07/30 19:27
阅读 426
收藏 0

根据系统日志发现每当数据量在100条都会报错连接超时不是到是不是数据太大得原因,我是dbcp连接池.原来是jdbc写的,因为会报错所以改成现在得,但是问题还是存在,求大家帮忙解答哈,很急,谢谢了.代码如下:


系统错误日志第一部分:

2015-07-30 11:11:27,671 [Thread-3] INFO  [com.epri.utils.JdbcUtil] - 获得数据库连接成功!
2015-07-30 11:11:27,984 [Thread-3] INFO  [com.epri.cms.RTM_CoverIce] - 插入覆冰装置 20M00000016675865的历史数据
2015-07-30 11:11:27,984 [Thread-3] INFO  [com.epri.utils.JdbcUtil] - 获得数据库连接成功!
2015-07-30 11:11:28,281 [Thread-3] INFO  [com.epri.utils.JdbcUtil] - 获得数据库连接成功!
2015-07-30 11:11:28,390 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodDirector] - I/O exception (java.net.ConnectException) caught when processing request: Connection refused: connect
2015-07-30 11:11:28,390 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodDirector] - Retrying request
2015-07-30 11:11:29,578 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodDirector] - I/O exception (java.net.ConnectException) caught when processing request: Connection refused: connect
2015-07-30 11:11:29,578 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodDirector] - Retrying request
2015-07-30 11:11:30,671 [Thread-2] ERROR [org.codehaus.xfire.transport.http.HttpChannel] - java.net.ConnectException: Connection refused: connect
2015-07-30 11:11:30,671 [Thread-2] ERROR [com.epri.utils.Sender] - org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Couldn't send message.
2015-07-30 11:11:31,343 [Thread-2] INFO  [com.epri.listener.OfficialRunable] - xml..<?xml version="1.0" encoding="utf-8"?><request><monitordata cmaid="20M00000013347776" nodecount="1"><datanode sensorid="20M00000017213389"><type>018001</type><equipmentid>20M00000003922586</equipmentid><timestamp>2015-07-17 19:29:09</timestamp><attrs><attr name="AVERAGE_WINDSPEED" value="0.0" alarm="FALSE" /><attr name="AVERAGE_WINDDIRECTION" value="0" alarm="FALSE" /><attr name="MAX_WINDSPEED" value="0.0" alarm="FALSE" /><attr name="EXTREME_WINDSPEED" value="0.0" alarm="FALSE" /><attr name="STANDARD_WINDSPEED" value="0.0" alarm="FALSE" /><attr name="AIR_TEMPERATURE" value="0.0" alarm="FALSE" /><attr name="HUMIDITY" value="0" alarm="FALSE" /><attr name="AIR_PRESSURE" value="0.0" alarm="FALSE" /><attr name="PRECIPITATION" value="0.0" alarm="FALSE" /><attr name="PRECIPITATION_INTENSITY" value="0.0" alarm="FALSE" /><attr name="RADIATION_INTENSITY" value="0" alarm="FALSE" /></attrs></datanode></monitordata></request>
2015-07-30 11:11:31,343 [Thread-3] INFO  [com.epri.cms.RTM_CoverIce] - 修改覆冰装置 20M00000016675865的最新数据
2015-07-30 11:11:31,343 [Thread-3] INFO  [com.epri.utils.JdbcUtil] - 获得数据库连接成功!
2015-07-30 11:11:31,359 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodBase] - Discarding unexpected response: HTTP/1.1 100 Continue
2015-07-30 11:11:31,390 [Thread-3] INFO  [com.epri.cms.RTM_CoverIce] - 覆冰数据不存在,修改CMSremark
2015-07-30 11:11:31,390 [Thread-3] INFO  [com.epri.listener.CmsRunable] - RTM_ICE_M数据推送完成
2015-07-30 11:11:31,390 [Thread-3] INFO  [com.epri.utils.JdbcUtil] - 获得数据库连接成功!
2015-07-30 11:11:31,437 [Thread-2] INFO  [com.epri.utils.Sender] - ......正式结果............0
2015-07-30 11:11:31,890 [Thread-2] INFO  [com.epri.utils.JdbcUtil] - 获得数据库连接成功!
2015-07-30 11:11:32,718 [Thread-3] INFO  [com.epri.listener.CmsRunable] - RTM_TEMPER_M数据100条
2015-07-30 11:11:32,734 [Thread-3] INFO  [com.epri.utils.JdbcUtil] - 获得数据库连接成功!
2015-07-30 11:11:33,515 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodDirector] - I/O exception (java.net.ConnectException) caught when processing request: Connection refused: connect
2015-07-30 11:11:33,515 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodDirector] - Retrying request
2015-07-30 11:11:34,500 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodDirector] - I/O exception (java.net.ConnectException) caught when processing request: Connection refused: connect
2015-07-30 11:11:34,500 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodDirector] - Retrying request
2015-07-30 11:11:35,484 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodDirector] - I/O exception (java.net.ConnectException) caught when processing request: Connection refused: connect
2015-07-30 11:11:35,484 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodDirector] - Retrying request
2015-07-30 11:11:36,578 [Thread-2] ERROR [org.codehaus.xfire.transport.http.HttpChannel] - java.net.ConnectException: Connection refused: connect
2015-07-30 11:11:36,578 [Thread-2] ERROR [com.epri.utils.Sender] - org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Couldn't send message.
2015-07-30 11:11:50,203 [Thread-2] INFO  [com.epri.listener.OfficialRunable] - xml..<?xml version="1.0" encoding="utf-8"?><request><monitordata cmaid="20M00000013347776" nodecount="1"><datanode sensorid="20M00000017213401"><type>018001</type><equipmentid>20M00000003908583</equipmentid><timestamp>2015-07-17 19:29:05</timestamp><attrs><attr name="AVERAGE_WINDSPEED" value="0.0" alarm="FALSE" /><attr name="AVERAGE_WINDDIRECTION" value="0" alarm="FALSE" /><attr name="MAX_WINDSPEED" value="0.0" alarm="FALSE" /><attr name="EXTREME_WINDSPEED" value="0.0" alarm="FALSE" /><attr name="STANDARD_WINDSPEED" value="0.0" alarm="FALSE" /><attr name="AIR_TEMPERATURE" value="0.0" alarm="FALSE" /><attr name="HUMIDITY" value="0" alarm="FALSE" /><attr name="AIR_PRESSURE" value="0.0" alarm="FALSE" /><attr name="PRECIPITATION" value="0.0" alarm="FALSE" /><attr name="PRECIPITATION_INTENSITY" value="0.0" alarm="FALSE" /><attr name="RADIATION_INTENSITY" value="0" alarm="FALSE" /></attrs></datanode></monitordata></request>
2015-07-30 11:11:50,203 [Thread-3] INFO  [com.epri.utils.JdbcUtil] - 获得数据库连接成功!
2015-07-30 11:11:50,218 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodBase] - Discarding unexpected response: HTTP/1.1 100 Continue
2015-07-30 11:11:50,281 [Thread-2] INFO  [com.epri.utils.Sender] - ......正式结果............0
2015-07-30 11:11:50,453 [Thread-2] INFO  [com.epri.utils.JdbcUtil] - 获得数据库连接成功!
2015-07-30 11:11:50,453 [Thread-3] INFO  [com.epri.cms.RTM_Weather] - 插入导线温度装置 


错误日志第二部分:

2015-07-30 11:13:51,046 [Thread-2] INFO  [com.epri.utils.JdbcUtil] - 获得数据库连接成功!
2015-07-30 11:13:53,531 [Thread-2] INFO  [com.epri.listener.OfficialRunable] - RTM_TEMPER_M数据1条
2015-07-30 11:13:53,531 [Thread-2] INFO  [com.epri.listener.OfficialRunable] - xml..<?xml version="1.0" encoding="UTF-8"?><request><monitordata cmaid="20M00000013347776" nodecount="1"><datanode sensorid="20M00000017213386"><type>013002</type><equipmentid>20M00000003908577</equipmentid><timestamp>2015-07-30 11:15:16</timestamp><attrs><attr name="LINE_TEMPERATURE1" value="43.18197" alarm="FALSE" /><attr name="LINE_TEMPERATURE2" value="43.18197" alarm="FALSE" /></attrs></datanode></monitordata></request>
2015-07-30 11:13:53,546 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodBase] - Discarding unexpected response: HTTP/1.1 100 Continue
2015-07-30 11:13:53,640 [Thread-2] INFO  [com.epri.utils.Sender] - ......正式结果............0
2015-07-30 11:13:53,640 [Thread-2] INFO  [com.epri.utils.JdbcUtil] - 获得数据库连接成功!
2015-07-30 11:13:54,609 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodDirector] - I/O exception (java.net.ConnectException) caught when processing request: Connection refused: connect
2015-07-30 11:13:54,609 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodDirector] - Retrying request
2015-07-30 11:13:55,593 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodDirector] - I/O exception (java.net.ConnectException) caught when processing request: Connection refused: connect
2015-07-30 11:13:55,593 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodDirector] - Retrying request
2015-07-30 11:13:56,687 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodDirector] - I/O exception (java.net.ConnectException) caught when processing request: Connection refused: connect
2015-07-30 11:13:56,687 [Thread-2] INFO  [org.apache.commons.httpclient.HttpMethodDirector] - Retrying request
2015-07-30 11:13:57,781 [Thread-2] ERROR [org.codehaus.xfire.transport.http.HttpChannel] - java.net.ConnectException: Connection refused: connect
2015-07-30 11:13:57,781 [Thread-2] ERROR [com.epri.utils.Sender] - org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Couldn't send message.
2015-07-30 11:13:57,781 [Thread-2] INFO  [com.epri.utils.JdbcUtil] - 获得数据库连接成功!
2015-07-30 11:13:57,781 [Thread-2] INFO  [com.epri.listener.OfficialRunable] - RTM_FILTHY_M数据0条
2015-07-30 11:13:57,781 [Thread-2] INFO  [com.epri.utils.JdbcUtil] - 获得数据库连接成功!
2015-07-30 11:13:57,796 [Thread-2] INFO  [com.epri.listener.OfficialRunable] - RTM_TOWER_EAXM_M数据0条
2015-07-30 11:13:57,796 [Thread-2] INFO  [com.epri.utils.JdbcUtil] - 获得数据库连接成功!
2015-07-30 11:13:57,796 [Thread-2] INFO  [com.epri.listener.OfficialRunable] - RTM_TOWER_SECURITY_M数据0条
2015-07-30 11:13:57,796 [Thread-2] INFO  [com.epri.utils.JdbcUtil] - 获得数据库连接成功!
2015-07-30 11:13:57,812 [Thread-2] INFO  [com.epri.listener.OfficialRunable] - RTM_GALLOPING_M数据0条
2015-07-30 11:13:57,812 [Thread-2] INFO  [com.epri.listener.OfficialRunable] - 用时:617281




部分代码:

class CmsRunable
  implements Runnable
{
  private Logger logger = MyLogger.getLogger(CmsRunable.class);


  public void run() {
    try {
      Properties properties = PropertiesUtil.getConfigProperties();


      String[] tableNames = properties.getProperty("table_names").split(
        "~");
      while (true) {
        for (int i = 0; i < tableNames.length; i++) {
          if (tableNames[i].equals("RTM_IMAGE_M")) {
            List list = 
              ImageDao.getList("select * from RTM_IMAGE_M where cmsremark='0'");
            int size = list.size();
            this.logger.info("RTM_IMAGE_M数据" + size + "条");
            for (int j = 0; j < size; j++) {
              Image image = (Image)list.get(j);
              String xml = image.getXml();
              ParseXmlAndSendToCMS.sendImageToCms(xml, image, 
                tableNames[i]);
            }
            this.logger.info("图像数据推送完成");
          } else {
            List list = OtherDataDao.getList("select * from " + tableNames[i] + " where cmsremark='0'");
            int size = list.size();
            this.logger.info(tableNames[i] + "数据" + size + "条");
            for (int j = 0; j < size; j++) {
              OtherData od = (OtherData)list.get(j);
              String xml = "";
              try {
                Clob clob = od.getXml();
                xml = clob.getSubString(1L, (int)clob.length());
              } catch (SQLException e) {
                this.logger.error("SendToCMSRunable从数据库中拿取xml报文失败");
              }


              ParseXmlAndSendToCMS.sendDataToCms(xml, od, tableNames[i]);
            }
            this.logger.info(tableNames[i] + "数据推送完成");
          }
        }


        JdbcUtil.closeConnection();
        Thread.sleep(60000L);
      }
    } catch (InterruptedException e) {
      this.logger.error("SendToCMSRunable 发送程序异常退出");
    }
  }
}


public class OfficialRunable
implements Runnable
{
private Logger logger = MyLogger.getLogger(OfficialRunable.class);


public void run() {
long begin=System.currentTimeMillis();
  try {
    Properties properties = PropertiesUtil.getConfigProperties();
    Properties cmaproperties = PropertiesUtil.getCmaConfigProperties();


    String[] tableNames = properties.getProperty("table_names").split(
      "~");
    while (true) {
      for (int i = 0; i < tableNames.length; i++) {
        if (tableNames[i].equals("RTM_IMAGE_M"))
        {
          List list = ImageDao.getList("select * from " + tableNames[i] + " where remark='0'  and time >to_char(to_date(ADD_MONTHS(sysdate, -1)),'yyyy-mm-dd') and o_remark is null");
          int size = list.size();
          this.logger.info("RTM_IMAGE_M数据" + size + "条");
          for (int j = 0; j < list.size(); j++) {
            Image image = (Image)list.get(j);
            String xml = image.getXml();
            String devicecode = "";
            devicecode = xml.substring(xml.indexOf("sensorid=") + 10, xml.indexOf("sensorid=") + 27);


            String cmaValue = (String)cmaproperties.get(devicecode);
            if (cmaValue == null) {
              this.logger.info("没有配置devicecode:" + devicecode);
            }
            else
            {
              String url = PropertiesUtil.getHostProperties().getProperty("server_uri");


              String url_test = PropertiesUtil.getHostProperties().getProperty("server_uri2");
              String sql = "update " + tableNames[i] + " t set remark='1' where id ='" + image.getId() + "'";
              String sql_oremark = "update " + tableNames[i] + " t set o_remark='1' where id ='" + image.getId() + "'";
              try
              {
                Sender.sendImageAndXml(xml, image, null, sql, sql_oremark, url);
              } catch (Exception e) {
                this.logger.info("正式环境未推送成功!");
              }


              try
              {
                Sender.sendImageAndXml(xml, image, null, sql, url_test);
              } catch (Exception e) {
                this.logger.info("测试环境未推送成功!");
              }
            }
          }
        } else {
          List list = OtherDataDao.getList("select * from " + tableNames[i] + " where  remark='0'  and time >to_char(to_date(ADD_MONTHS(sysdate, -1)),'yyyy-mm-dd')  and o_remark is null order by time desc");
          int size = list.size();
          this.logger.info(tableNames[i] + "数据" + size + "条");


          for (int j = 0; j < list.size(); j++) {
            OtherData as = (OtherData)list.get(j);
            String xml = "";
            String devicecode = "";
            try {
              Clob clob = as.getXml();
              xml = clob.getSubString(1L, (int)clob.length());
              devicecode = xml.substring(xml.indexOf("sensorid=") + 10, xml.indexOf("sensorid=") + 27);


              String cmaValue = (String)cmaproperties.get(devicecode);
              if (cmaValue == null) {
                this.logger.info("没有配置devicecode:" + devicecode);
                continue;
              }
              this.logger.info("xml.." + xml);
            } catch (SQLException e) {
              this.logger.error("CallNariRunable从数据库中拿取xml报文失败");
            }


            String url = PropertiesUtil.getHostProperties().getProperty("server_uri");


            String url_test = PropertiesUtil.getHostProperties().getProperty("server_uri2");


            String sql = "update " + tableNames[i] + " t set remark='1' where id ='" + as.getId() + "'";
            String sql_oremark = "update " + tableNames[i] + " t set o_remark='1' where id ='" + as.getId() + "'";
            try
            {
              Sender.sendImageAndXml(xml, null, as, sql, sql_oremark, url);
            } catch (Exception e) {
              e.printStackTrace();
              this.logger.info("正式环境未推送成功!");
            }


            try
            {
              Sender.sendImageAndXml(xml, null, as, sql, url_test);
            } catch (Exception e) {
              e.printStackTrace();
              this.logger.info("测试环境未推送成功!");
            }
          }
        }
      }
      long end =System.currentTimeMillis();
      logger.info("用时:"+(end-begin));
      Thread.sleep(700000L);
    }
  }
  catch (InterruptedException e) {
    this.logger.error("CallNariRunable 发送程序异常退出");
  }
}
}


public class Sender
{
  public static String ipStr = null;
  public static Integer port = null;
  public static DatagramSocket sendSocket = null;
  public static InetAddress ip = null;
  private static Logger logger = MyLogger.getLogger(Sender.class);


  public static byte[] blobToBytes(Blob blob)
  {
    BufferedInputStream is = null;
    try {
      is = new BufferedInputStream(blob.getBinaryStream());
      byte[] bytes = new byte[(int)blob.length()];
      int len = bytes.length;
      int offset = 0;
      int read = 0;
      while ((offset < len) && 
        ((read = is.read(bytes, offset, len - offset)) >= 0)) {
        offset += read;
      }
      byte[] arrayOfByte1 = bytes;
      return arrayOfByte1;
    }
    catch (Exception e)
    {
      return null;
    } finally {
      try {
        is.close();
        is = null;
      } catch (IOException e) {
        return null;
      }
    }
  }


  public static void sendImageAndXml(String strXml, Image image, OtherData as, String sql, String sql_oremark, String url) {
    CMSCAGAccessServiceClient client = new CMSCAGAccessServiceClient(url);
    try {
      String obj = null;
      if (image != null) {
        byte[] image_byte = blobToBytes(image.getImage());
        obj = client.getCMSCAGAccessServiceHttpPort().uploadCMAImage(image_byte, strXml);


        if (parseXML(obj).equals("0"))
        {
          ImageDao.setImageRemark(image, sql);
          logger.info("图像数据ID:" + image.getId() + "上传成功");
        } else {
          logger.info("图像数据ID:" + image.getId() + "上传失败");
          logger.info(obj);
          ImageDao.setImage_O_Remark(image, sql_oremark);
        }
      } else {
        obj = client.getCMSCAGAccessServiceHttpPort().uploadCMAData(strXml);
        logger.info("......正式结果............" + parseXML(obj));
        if (parseXML(obj).equals("0"))
        {
          OtherDataDao.setOtherDataRemark(as, sql);
          logger.info("ID:" + as.getId() + "上传成功");
        } else {
          logger.info("ID:" + as.getId() + "上传失败");
          logger.info(obj);
          OtherDataDao.setOtherData_O_Remark(as, sql_oremark);
        }
      }
    } catch (Exception e) {
      logger.error(e);
    }
  }


  public static void sendImageAndXml(String strXml, Image image, OtherData as, String sql, String url) {
    CMSCAGAccessServiceClient client = new CMSCAGAccessServiceClient(url);
    try {
      String obj = null;
      if (image != null) {
        byte[] image_byte = blobToBytes(image.getImage());
        obj = client.getCMSCAGAccessServiceHttpPort().uploadCMAImage(image_byte, strXml);


        if (parseXML(obj).equals("0"))
        {
          ImageDao.setImageRemark(image, sql);
          logger.info("图像数据ID:" + image.getId() + "上传成功");
        } else {
          logger.info("图像数据ID:" + image.getId() + "上传失败");
          logger.info(obj);
        }
      } else {
        obj = client.getCMSCAGAccessServiceHttpPort().uploadCMAData(strXml);
        logger.info("......测试结果............" + parseXML(obj));
        if (parseXML(obj).equals("0"))
        {
          OtherDataDao.setOtherDataRemark(as, sql);
          logger.info("ID:" + as.getId() + "上传成功");
        } else {
          logger.info("ID:" + as.getId() + "上传失败");
          logger.info(obj);
        }
      }
    } catch (Exception e) {
      logger.error(e);
    }
  }


  public static String parseXML(String obj) {
    SAXBuilder reader = new SAXBuilder();
    try {
      Document document = reader.build(new ByteArrayInputStream(obj.getBytes()));
      Element root = document.getRootElement();
      Element result = root.getChild("result");
      return result.getAttributeValue("code");
    }
    catch (JDOMException e) {
      e.printStackTrace();
    }
    catch (IOException e) {
      e.printStackTrace();
    }
    return null;
  }
}




加载中
返回顶部
顶部