2 meilixinteng meilixinteng 于 2016.09.19 10:09 提问

mq问题,谁能给注释一下。看不懂了 2C

package com.dcsoft.sdfq.activeMq.sender;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.log4j.Logger;
import com.dcsoft.sdfq.activeMq.db.DBQuery;
import com.dcsoft.sdfq.activeMq.util.LoadProperties;
import com.dcsoft.sdfq.activeMq.util.ToolSupport;

import dba.DBMap;

public class SendMessageThread extends Thread {

public static Logger log = Logger.getLogger(SendMessageThread.class);

private SmsMQSender sms = null;

private String clientIpTemp = "";

public SendMessageThread(String id) {
    super(id);
}

public void run() {
    // 与消息中间件进行通讯的对象
    sms = new SmsMQSender();
    // 获取本地客户端ip
    String ips = null;
    String[] strs = getAllIP();
    if (strs != null && strs.length > 0) {
        String ipPrefix = LoadProperties.getInstance().readINI("clientID");
        ips = ipPrefix;
    }
    if (ips == null)
        return;
    clientIpTemp = "tcp://" + ips + ":6161";

    while (true) {
        // CheckExistsMessage.check();
        checkAndSend();
        SendMessageThread smt = (SendMessageThread) Thread.currentThread();
        smt.shortWaiting();
    }
}

private void checkAndSend() {
    String returnID = "";
    ResultSet rst, sscs, xzqh = null;
    try {
        DBQuery db = new DBQuery();
        // 查询任务表
        String sql = "SELECT TOP 1 * FROM tbl_sender WHERE senderType = 0";
        ResultSet rs = db.executeQuery(sql);
        if (rs.next()) {
            String id = rs.getString("id");
            String tblName = rs.getString("tblName");
            String idName = rs.getString("idName");
            String idValue = rs.getString("idValue");
            String dealType = rs.getString("dealType");
            String clxxid = rs.getString("clxxid");
            String dataType = rs.getString("dataType");
            String chp = rs.getString("cph");
            db.closeAll();

            // 查询需要同步的数据
            if (dealType.equals("delete")) {
                db = new DBQuery();
                String sqlDel = "update " + tblName + " set datatype='2' where " + idName + " = '" + idValue + "'";
                db.executeUpdate(sqlDel);
                db.closeAll();
                sql = "select '" + idValue + "' as " + idName;
            } else
                sql = "select * from " + tblName + " where " + idName + " = '" + idValue + "'";
            rs.close();
            rs = null;
            db = new DBQuery();
            rs = db.executeQuery(sql);
            DBMap dbmap = new DBMap(rs, tblName, id, clientIpTemp, idName, dealType, clxxid, idValue, dataType, chp, new ToolSupport()
                    .getCityByDwbm(LoadProperties.getInstance().readINI("dwbh")), new ToolSupport().getXzqhByDwbm(LoadProperties.getInstance().readINI(
                    "dwbh")));
            db.closeAll();
            if (dbmap.isEmpty()) {
                sql = "delete from tbl_sender where (tblName = '" + tblName + "' and idValue = '" + idValue + "') ";
                db = new DBQuery();
                db.executeUpdate(sql);
                db.closeAll();
                return;
            }
            // 发送消息
            returnID = sms.sendMessage(dbmap);

            if (!returnID.equalsIgnoreCase("")) {
                sql = "UPDATE tbl_sender SET senderType = 1, sendtime = getdate() WHERE id = '" + returnID + "'";
                db = new DBQuery();
                db.executeUpdate(sql);
                db.closeAll();
            }
        } else {
            db.closeAll();
            SendMessageThread smt = (SendMessageThread) Thread.currentThread();
            smt.longWaiting();
        }
    } catch (SQLException e) {
        log.info("SendMessageThread 异常1:" + e);
        SendMessageThread smt = (SendMessageThread) Thread.currentThread();
        smt.longWaiting();
    } catch (Exception e) {
        log.info("SendMessageThread 异常2:" + e);
        SendMessageThread smt = (SendMessageThread) Thread.currentThread();
        smt.longWaiting();
    }
    return;
}

void shortWaiting() {
    try {
        sleep(Integer.parseInt(LoadProperties.getInstance().readINI("clientSenderThreadTime"))); // 发送消息
    } catch (Exception e) {
        log.info("SendMessageThread.java 休眠异常" + e);
    }
}

void MiddleWaiting() {
    try {
        sleep(Integer.parseInt(LoadProperties.getInstance().readINI("clientSenderThreadMiddleTime")));// 中断情况
    } catch (Exception e) {
        log.info("SendMessageThread.java 休眠异常" + e);
    }
}

void longWaiting() {
    try {
        sleep(Integer.parseInt(LoadProperties.getInstance().readINI("clientSenderThreadLongTime"))); // 异常情况
    } catch (Exception e) {
        log.warn("SendMessageThread.java 休眠异常" + e);
    }
}

public static String[] getAllIP() {
    try {
        InetAddress localHost = InetAddress.getLocalHost();
        String hostName = localHost.getHostName();
        InetAddress[] inetAdds = InetAddress.getAllByName(hostName);
        String[] ips = new String[inetAdds.length];
        for (int i = 0; i < inetAdds.length; i++)
            ips[i] = inetAdds[i].getHostAddress();
        return ips;
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    return null;
}

}

1个回答

zqbnqsdsmd
zqbnqsdsmd   2016.09.28 01:13
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
金山词霸---极速版
金山词霸极速版---看不懂了就翻译一下 很方便
BIOS对照表
有了这个再也不用担心看不懂了,
C++课件,从入门到进阶(英文版)
我是看不懂了,国外纯正版,给大家分享了!!!
unix环境高级编程英文版
unix环境高级编程英文版,方便查阅,有时候中文的可能看不明白,看看英文就懂了
用c#编写的【计算器】
用c#编写的【计算器】,里面代码有点乱,自己都看不懂了,真是对不住大家了
plsql数据库
plsql压缩包,自带中文,再也不怕看不懂了,经实测可以正常使用
最新应用程序反编译器
应用程序反编译,轻松获取源代码。不用再怕看不懂了,很轻松的
Java api1.8中文版本
最新Java jdk 1.8中文版本, 再也不用担心英语看不懂了.
IMB MQ 报错问题记录
IMB MQ 报错问题记录
WebSphere MQ问题知识库
WebSphere MQ问题知识库WebSphere MQ问题知识库