在我的项目中使用:Java6,Struts 1,JSP。
在some.jsp页面中有几行代码:
try {
ExecutorService exService = Executors.newSingleThreadExecutor();
FutureTask task = new FutureTask(new Callable() {
public String call() throws Exception {
String rez = org.apache.commons.io.IOUtils.toString((
new java.net.URL("http://" + server + ":8080/nginx_status")).openStream());
return rez;
}
});
exService.execute(task);
String rez = (String) task.get(300, TimeUnit.MILLISECONDS);
if (rez == null) System.out.println("Server " + server + " is not responsible in 300 ms");
System.out.println("Server " + server + " status: " +rez);
} catch (Exception ex) {
System.out.println("Server " + server + " is not responsible");
}
}
} catch (Exception ex) {
System.out.print("Status information: cannot find servers adress");
}
执行代码后,在控制台上显示以下代码行:
服务器localhost不负责
可能是什么问题?