作者 朱兆平

发送线程加锁

@@ -38,7 +38,7 @@ public class IMFNoDelaySender extends Thread{ @@ -38,7 +38,7 @@ public class IMFNoDelaySender extends Thread{
38 this.sqlMax=sqlMax; 38 this.sqlMax=sqlMax;
39 } 39 }
40 40
41 - public void run() { 41 + public synchronized void run() {
42 try { 42 try {
43 43
44 if (this.client == null) { 44 if (this.client == null) {
@@ -48,7 +48,7 @@ public class IMFNoDelaySender extends Thread{ @@ -48,7 +48,7 @@ public class IMFNoDelaySender extends Thread{
48 48
49 while(true) { 49 while(true) {
50 //初始化读取 50 //初始化读取
51 - logger.info("job start:"); 51 + logger.info("job start,发送线程开始:");
52 int lastFID = Utils.readFIDIndex(this.indexFileName); 52 int lastFID = Utils.readFIDIndex(this.indexFileName);
53 int maxFID = this.dao.getMaxFID(sqlMax); 53 int maxFID = this.dao.getMaxFID(sqlMax);
54 logger.info("lastROW=" + lastFID + " maxCount=" + maxFID); 54 logger.info("lastROW=" + lastFID + " maxCount=" + maxFID);
@@ -119,9 +119,7 @@ public class IMFNoDelaySender extends Thread{ @@ -119,9 +119,7 @@ public class IMFNoDelaySender extends Thread{
119 // sendMsg = newXml.finalXmlStr(); 119 // sendMsg = newXml.finalXmlStr();
120 120
121 if (!"".equals(sendMsg)) { 121 if (!"".equals(sendMsg)) {
122 - logger.info("开始发送数据 XML:" + sendMsg);  
123 - String is_send_ok = this.client.sendMSG(sendMsg);  
124 - logger.info("is_send_ok=" + is_send_ok); 122 + sendXml(sendMsg);
125 is_ok = Utils.writeFIDIndex(this.indexFileName, m.getRownum_()); //发送成功写入节点文件 123 is_ok = Utils.writeFIDIndex(this.indexFileName, m.getRownum_()); //发送成功写入节点文件
126 logger.debug("FID:" + m.getFid() + " 缓存成功"); 124 logger.debug("FID:" + m.getFid() + " 缓存成功");
127 ++times; 125 ++times;
@@ -138,6 +136,7 @@ public class IMFNoDelaySender extends Thread{ @@ -138,6 +136,7 @@ public class IMFNoDelaySender extends Thread{
138 }else { 136 }else {
139 try { 137 try {
140 Thread.sleep(10000L); 138 Thread.sleep(10000L);
  139 + logger.info("发送线程休眠");
141 } catch (InterruptedException var3) { 140 } catch (InterruptedException var3) {
142 var3.printStackTrace(); 141 var3.printStackTrace();
143 } 142 }
@@ -150,6 +149,12 @@ public class IMFNoDelaySender extends Thread{ @@ -150,6 +149,12 @@ public class IMFNoDelaySender extends Thread{
150 } 149 }
151 } 150 }
152 151
  152 + public synchronized void sendXml(String msg){
  153 + logger.info("线程:::"+Thread.currentThread().getName()+"开始发送数据 XML:" + msg);
  154 + String is_send_ok = this.client.sendMSG(msg);
  155 + logger.info("发送回执=" + is_send_ok);
  156 + }
  157 +
153 private static String tranlateXML(String xml) throws Exception { 158 private static String tranlateXML(String xml) throws Exception {
154 String stype = XMPParse.getNodeValueFromXmlString(xml, "/MSG/META/STYP"); 159 String stype = XMPParse.getNodeValueFromXmlString(xml, "/MSG/META/STYP");
155 if (!StringUtils.isBlank(stype)) { 160 if (!StringUtils.isBlank(stype)) {