zoukankan      html  css  js  c++  java
  • 20 线程中添加超时的方法

       isExecSuccess=false;
            exitCode=-1;
            Thread newThread=new Thread(new Runnable() {
              @Override
              public void run() {
                try {
                  exitCode= process.waitFor();
                  isExecSuccess=true;
                } catch (InterruptedException e) {
                  e.printStackTrace();
                }
              }
            });
            newThread.start();
            long startTime=System.currentTimeMillis();
            long currentTime;
            long timeOut=0;
            while (timeOut< this.ftpCommandTimeout && !isExecSuccess){
              Thread.sleep(10);
              currentTime=System.currentTimeMillis();
              timeOut=currentTime-startTime;
            }
            if(newThread.isAlive()){
              newThread.interrupt();
            }
    isExecSuccess=false;
    exitCode=-1;
    Thread newThread=new Thread(new Runnable() {
    @Override
    public void run() {
    try {
    exitCode= process.waitFor();
    isExecSuccess=true;
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }
    });
    newThread.start();
    long startTime=System.currentTimeMillis();
    long currentTime;
    long timeOut=0;
    while (timeOut< this.ftpCommandTimeout && !isExecSuccess){
    Thread.sleep(10);
    currentTime=System.currentTimeMillis();
    timeOut=currentTime-startTime;
    }
    if(newThread.isAlive()){
    newThread.interrupt();
    }
  • 相关阅读:
    hadoop集群无法找到datanode节点问题解决
    Startup.A51说明(上)
    UCOSII基础之数据结构
    FPGA之难度
    UCOSII学习笔记【二】
    (转)PCB中各层的含义(protel中)
    UCOSII学习笔记 一
    查看51汇编,解决奇怪的问题
    滑雪
    HMM的理解
  • 原文地址:https://www.cnblogs.com/yangh2016/p/6000871.html
Copyright © 2011-2022 走看看