final ExecutorService exec = Executors.newFixedThreadPool(1);
Integer status=0;
Callable<Integer> call = new Callable<Integer>() {
public Integer call() throws Exception {
//开始执行任务
Integer type=Integer.valueOf(HTTPSRequestUtil.httpsGetSyncRequest(url));
return type;
}
};
try {
Future<Integer> future = exec.submit(call);
Integer obj = future.get(1000 * 5, TimeUnit.MILLISECONDS); //任务处理超时时间设为 1 秒
status=obj;
System.out.println("任务成功返回:" + status);
} catch (TimeoutException ex) {
status=10;
System.out.println("处理超时啦...."+ status);
} catch (Exception e) {
status=10;
System.out.println("处理失败."+status);
}
// 关闭线程池
exec.shutdown();
return status;
Integer status=0;
Callable<Integer> call = new Callable<Integer>() {
public Integer call() throws Exception {
//开始执行任务
Integer type=Integer.valueOf(HTTPSRequestUtil.httpsGetSyncRequest(url));
return type;
}
};
try {
Future<Integer> future = exec.submit(call);
Integer obj = future.get(1000 * 5, TimeUnit.MILLISECONDS); //任务处理超时时间设为 1 秒
status=obj;
System.out.println("任务成功返回:" + status);
} catch (TimeoutException ex) {
status=10;
System.out.println("处理超时啦...."+ status);
} catch (Exception e) {
status=10;
System.out.println("处理失败."+status);
}
// 关闭线程池
exec.shutdown();
return status;