Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

BufferedReader.readline() performance problems

807569Sep 14 2006 — edited Sep 15 2006
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 13 2006
Added on Sep 14 2006
5 comments
1,194 views