作者 朱兆平

代理人发送主线程 线程保护子线程

... ... @@ -46,9 +46,22 @@ public class Main {
if (LOGIN_OK && client != null) {
logger.info("start run Timer,client hasocde=" + client.hashCode());
while (true){
if(!AgentSender.isrunning){
AgentSender send = new AgentSender(client);
send.start();
}
try {
Thread.sleep(50000);
} catch (Exception e) {
e.printStackTrace();
logger.info(e.getMessage());
}
}
//代理人发送程序
AgentSender send = new AgentSender(client);
send.start();
//数据仓库给九州的发送程序
// Timer timer = new Timer();
... ...
... ... @@ -11,7 +11,8 @@ public class AgentSender extends Thread{
private static final Logger logger = Logger.getLogger(AgentSender.class);
public volatile boolean bool = false;
public static boolean isrunning;
Jedis jedis = new Jedis("10.50.3.73", 6379);
private IMFClient client;
... ... @@ -24,47 +25,77 @@ public class AgentSender extends Thread{
public void run(){
logger.info(jedis);
while(!bool){
try {
if (this.client == null) {
logger.info("IMFClient has been closed");
return;
}
isrunning=true;
if(Main.isSuc){
logger.info("《《《主线程初始化成功。。。。》》》");
if(Main.LOGIN_OK){
String SendMsg = jedis.rpoplpush("task-queue", "tmp-queue"); //取队列消息
//队列消息不为NULL开始发送
if(SendMsg !=null && SendMsg.length() != 0){
logger.info("《《《已读取队列消息,请关注下方发送信息LOG回显》》》");
try{
String returnMsg = client.sendMSG(SendMsg);
logger.debug("<<发送返回的信息:"+returnMsg+">>");
//9是发送成功
if(returnMsg.indexOf("<CODE>9</CODE>")>=0){
jedis.rpop("tmp-queue");
logger.debug("<<移除队列>>");
}else{
//如果发送不成功继续发送
jedis.rpoplpush("tmp-queue", "task-queue");
logger.info("!!<<执行未成功发送的消息返回到发送消息队列>>!!");
}
}catch (Exception e){
e.printStackTrace();
logger.info("!!<<请注意!发送异常====>>!!");
logger.info("《《《登录成功开始轮询500mm一次。。。。》》》");
while(true){
String SendMsg = jedis.rpoplpush("task-queue", "tmp-queue"); //取队列消息
//队列消息不为NULL开始发送
if(SendMsg !=null && SendMsg.length() != 0){
String returnMsg = this.client.sendMSG(SendMsg);
logger.debug("<<发送返回的信息:"+returnMsg+">>");
//9是发送成功
if(returnMsg.indexOf("<CODE>9</CODE>")>=0){
try {
jedis.rpop("tmp-queue");
logger.debug("<<移除队列>>");
} catch (Exception e) {
e.printStackTrace();
logger.info(e.getMessage());
logger.info("!!移除队列失败!!");
}
}else{
//如果发送不成功继续发送
try{
jedis.rpoplpush("tmp-queue", "task-queue");
logger.info("!!<<执行未成功发送的消息返回到发送消息队列>>!!");
}catch (Exception e){
e.printStackTrace();
logger.info(e.getMessage());
logger.info("!!回写TMP到TASK队列失败!!");
}
}
}
}else {
logger.info("*********当前队列为空*********");
//发送延迟
try {
Thread.sleep(500);
} catch (Exception e) {
e.printStackTrace();
logger.info(e.getMessage());
}
}
}else{
logger.info("---------登陆中");
}
try {
Thread.sleep(500);//发送延迟
} catch (Exception e) {
e.printStackTrace();
}
}
}catch (Exception var14) {
var14.printStackTrace();
logger.info(var14.getMessage());
}
isrunning=false;
logger.info("---------线程不在了");
}
}
... ...