⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pushthread.java

📁 WAP PUSH后台源码,WAP PUSH后台源码
💻 JAVA
字号:
package push.test;

import java.io.IOException;
import java.sql.*;

import com.sxit.push.PushHQ2LC;
import com.sxit.push.PushHQ2LCService;
import com.sxit.push.PushHQ2LCServiceLocator;

public class PushThread extends Thread {
    public void run() {
        System.out.println("----wap push线程启动----");
        int times = 0;
        while (true) {
            try {
                int count = doExcute();
                if (count == 0) {
                    try {
                        System.out.println(new Timestamp(System.currentTimeMillis())+"-->没有PUSH,休息10秒");
                        sleep(10000L);
                    } catch (InterruptedException ie) {
                    }
                    if (++times == 2) {
                        times = 0;
                    }
                }
            } catch (IOException ioe) {
                System.out.println(ioe.getMessage());
            }

        }
    }

    public int doExcute() throws IOException {
        /* 发送次状态报告 */
      int count = 0;
        Connection conn = null;
        Statement stat = null;
        try {
            conn = DBUtil.getConnection();
            stat = conn.createStatement();
            ResultSet rs = stat.executeQuery("select id,frommdn,tomdn,title,url from tpush where status=0");
            while (rs.next()) {
                int id = rs.getInt(1);
                String fromMdn = rs.getString(2) ;
                String toMdn = rs.getString(3);
                String title = rs.getString(4);
                String url = rs.getString(5);
                String result = push(fromMdn,toMdn,title,url);
                int i1 = result.indexOf(":");
                int i2 = result.lastIndexOf(":");
                String sss = result.substring(i1 + 1, i2);
                System.out.println("result="+result);
                stat.execute("update tpush set status = 1 ,result = "+sss+" where id="+id);
                count++;
                if (count>5000)
                    break ;
            }
            rs.close();
        } catch (SQLException se) {
            System.out.println(se.getMessage());
        } finally {
            try {
                if (stat != null)
                    stat.close();
                stat = null;
            } catch (SQLException e) {
                System.out.println(e.getMessage());
            }
            try {
                if (conn != null) {
                    conn.close();
                }
                conn = null;
            } catch (SQLException e) {
                System.out.println(e.getMessage());
            }
        }
        return count;
    }
    public String push(String fromMdn,String toMdn,String title,String url)  {
        try {
	        PushHQ2LCService service = new PushHQ2LCServiceLocator();
	        PushHQ2LC pushHQ = service.getPushService();
	    	String result ="";
	    	result = pushHQ.pushMSG2LC("010","010",fromMdn,toMdn,title,url);
	    	return result ;
        } catch(Exception e) {
            e.printStackTrace();
            return e.getMessage();
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -