我现在做一个程序,用java链接的ftp服务器读取文件,因为有些ftp服务器当时不一定开启,在连接时候有20秒的延时,我做的程序是定时30秒遍历所有ftp服务器,这样造成好多后边服务器根本无法完成遍历便又重新开始,想请大家帮忙解决下,让程序在连接某一个服务器5秒内没有结果就自动转到下一个 public boolean open(String server, int port, String userName, String userPassword) {
try {
if (aftp.isConnected()) {
aftp.disconnect();
}
aftp = new FTPClient();
aftp.connect(server, port);
if (FTPReply.isPositiveCompletion(aftp.getReplyCode())) {
if (aftp.login(userName, userPassword)) {
aftp.setControlEncoding("UTF-8");
return true;
}
}
return false;
} catch (Exception e) {
e.printStackTrace();
return false;

}这是我的代码  不知道可以用定时器实现么javaftp服务器定时器