Is there an easy way to skip the readLine () method in java if it takes more than, say, 2 seconds?
Here is the context in which I ask this question:
public void run()
{
boolean looping = true;
while(looping) {
for(int x = 0; x<clientList.size(); x++) {
try {
Comm s = clientList.get(x);
String str = s.recieve();
}
}
}
}
Comm is the class I wrote, and the get method that contains the BufferedReader, called "in", is as follows:
public String recieve()
{
try { if(active) return in.readLine(); }
catch(Exception e) { System.out.println("Comm Error 2: "+e); }
return "";
}
I noticed that the program stops and waits for the input stream to read something before continuing. This is bad because I need a program to continue the loop (since it is a loop, it accesses all other clients and asks for input). Is there a way to skip the readLine () process if there is nothing to read?
I am also sure that I am not explaining it very well, so please ask me questions if I get confused.