超时方法

public static Boolean timeOutIsLogin(Integer times,String ip, String userName, String userPwd) {
Boolean obj = false;

final ExecutorService exec = Executors.newFixedThreadPool(1);
Callable<Boolean> call = new Callable<Boolean>() {
public Boolean call() throws Exception {


return ShellUtil.isLogin( ip, userName, userPwd) ;
}
};
//10秒后退出
try {
Future<Boolean> future = exec.submit(call);
obj = future.get(times * 1500, TimeUnit.MILLISECONDS); // 任务处理超时时间设为10秒
return obj;
} catch (Exception e) {
return false;
}

}
posted @ 2021-01-31 15:52  zzl0916  阅读(83)  评论(0编辑  收藏  举报