工做总结(1)

针对于手机端访问服务器端,中间件设置相应等待时间问题。

如果某个方法执行时间过长,超过等待时间会自动跳转到错误页面。针对此种情况可以将后台方法放到一个线程中,当访问后台时启动线程 执行方法。前台通过ajax轮询方式获取线程中方法的执行结果。

1.

public class XyThread {
    //线程ID
    private String id;
    
    //线程状态(
    //1执行中
    //2 执行结束
    private String status="1";
    
    //执行结果
    private String result;

}

2.

public class RunnableUtil implements Runnable {

    private Thread t;
    
    //线程名称
    private String threadName;
    
    private Map<String,XyThread> runningPublishTheads;
    
    //当前session
    private HttpSession session;
    
    //当前的request
    private HttpServletRequest request;
    
    public RunnableUtil(Map<String, XyThread> runningPublishTheads, String threadName, HttpSession session) {
        super();
        this.runningPublishTheads = runningPublishTheads;
        this.threadName = threadName;
        this.session = session;
    }

    @Override
    public void run() {
            System.out.println("成功进入了线程的run方法");
         
           System.out.println(runningPublishTheads.get("1"));
            System.out.println(t.getId());
            XyThread xyThread = new XyThread();
            xyThread.setId(t.getId()+"");
            xyThread.setStatus("1");
            runningPublishTheads.put("1", xyThread);
  
    }
    
    public void start () {
        System.out.println("Starting " +  threadName );
        if (t == null) {
           t = new Thread (this, threadName);
           t.start ();
        }
   }

}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值