java readline 超时_跳过Java中的BufferedReader readLine()方法
是否有一種簡單的方法可以跳過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()進程?
我也很確定我不能很好地解釋這一點,所以如果我感到困惑,請問我一些問題.
總結
以上是生活随笔為你收集整理的java readline 超时_跳过Java中的BufferedReader readLine()方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux回车换行符(linux回车)
- 下一篇: linux 安装ssh(linux 安装