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();
    }
  • 相关阅读:
    ssh
    步进器&分栏控制器
    一些过期的整理前端代码
    进度条和滑动条
    UISwitcher
    定时器
    创建window
    iOS开发---UIButton 1 //创建一个可以显示图片的按钮。
    iOS开发---UILabel
    今日头条前端编程题
  • 原文地址:https://www.cnblogs.com/yangh2016/p/6000871.html
Copyright © 2011-2022 走看看