消息接收线程

/**
 * [项目名]: 教育局桌面驻留程序
 * [模块名]: 消息接收线程
 * [文件名]: MessageThread.java
 * [文件实现功能]: 定时接收后台的消息
 * [作者]: ztc * [版本]: v1.0
 * [版权所有]:
 * -------
 * [备注]:
 *
 * -------
 * [修改记录]:
 * [ 日    期 ]     [版本]      [修 改 人]       [修 改 内 容]
 *  2013/09/06       1.0         ztc         创建
 * [遗留问题]:
 */
package com.education.view;
import com.education.bean.res;
import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONArray;
import org.json.JSONObject;

public class MessageThread extends Thread {

    @Override
    public void run() {
        while (true) {
            /**
             * 接收消息提醒
             */
            System.out.println(res.name);
            //向服务器请求消息数据
            byte[] returnByte = CustomerHttpClient.post(res.http + "/OA/oatool.do?method=getInformation&p_userId=" + res.name + "", null);
            if (null == returnByte || 0 == returnByte.length) {
                continue;
            }
            String ServerResponse = null;
            try {
                ServerResponse = new String(returnByte, "utf-8");
            } catch (UnsupportedEncodingException ex) {
                Logger.getLogger(MessageThread.class.getName()).log(Level.SEVERE, null, ex);
                continue;
            }
            try {//解析JSONA数据
                JSONArray jsonArray = new JSONArray(ServerResponse);
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject jsonObj = (JSONObject) jsonArray.get(i);
                    String msg = (String) jsonObj.get("msg");//消息内容
                    String url = (String) jsonObj.get("url");//消息url
                    //弹出消息提示框
                    new MessageBox(msg, url);
                }
            } catch (Exception ex) {
            }
            try {
                Thread.sleep(res.messageThreadTime * 1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(MessageThread.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值