Hi, I have been doing some profiling of my project and have found that one part of my code is extremely inefficient and uses around 95% of total processor time during runnning.
My program connects to a socket and reads input from that socket constantly, I have implemented it as a thread, and this is my run() method:
public void run()
{
System.out.println("Process Started");
stdIn = new BufferedReader(
new InputStreamReader(System.in));
out.println(""); // password, at the moment set as empty
try{
while (flag = true) {
String input = in.readLine();
panelInstance.loadDelay();
panelInstance.flashUpdatingRed();
flashRed red = new flashRed(panelInstance, timer);
}
}catch(IOException e){
System.out.println("Process Stopped");
}
}
As you can see, I use a while loop to constantly wait for output from the socket.
netBeans profiler is reporting that java.io.InputStreamReader.read(char[], int,int) is the methiod taking the processor time, and this is invoked by java.io.BufferedReader.readLine() that I use in my code.
Has anyone got any ideas, why this would be quite so inefficient??
Just to give you an idea, an average running time for my run() method is 160000 ms.
Thanks, any comments appreciated.
Cheers
Andy