是否有一种简单的方法可以跳过java中的readLine()方法(如果它花费的时间超过2秒)?
这是我问这个问题的背景:
public void run()
{
boolean looping = true;
while(looping) {
for(int x = 0; x
try {
Comm s = clientList.get(x);
String str = s.recieve();
// code that does something based on the string in the line above
}
// other stuff like catch methods
}
}
}
Comm是我编写的一个类,其中包含名为“ in”的BufferedReader的receive方法是这样的:
public String recieve()
{
try { if(active) return in.readLine(); }
catch(Exception e) { System.out.println("Comm Error 2: "+e); }
return "";
}
我注意到该程序停止并等待输入流读取某些内容,然后再继续.这很不好,因为我需要程序保持循环(循环时,它会转到所有其他客户端并要求输入).如果没有要读取的内容,是否可以跳过readLine()进程?
我也很确定我不能很好地解释这一点,所以如果我感到困惑,请问我一些问题.