views:

53

answers:

2

Hi everyone.

I have an Applet that makes a request to a Servlet. On the servlet it's using the PrintWriter to write the response back to Applet:

out.println("Field1|Field2|Field3|Field4|Field5......|Field10");

There are about 15000 records, so the out.println() gets executed about 15000 times.

Problem is that when the Applet gets the response from Servlet it takes about 15 minutes to process the records. I placed System.out.println's and processing is paused at around 5000, then after 15 minutes it continues processing and then its done.

Has anyone faced a similar problem? The servlet takes about 2 seconds to execute. So seems that the browser/Applet is too slow to process the records.

This is the Applet code. Sometimes it just stops on the first System.out and sometimes stops on the second System.out.

while ((line = in.readLine()) != null) {
    System.out.println("Reading from stream....");
    datavector.add(line);
    System.out.println("Vector size="+datavector.size()+"  Line added="+line);
}

Any ideas appreciated.

Thanks.

A: 

Is you question related to "processing being paused around 5000 records and then starts on its own after 15" ? OR it is processing being slow on your applet

It will be helpful if you code post some code snippet?

prasrob
Hi, well processing stops around after 5000 and then after like 15 minutes it starts again. So why does processing stops? What is Java doing?Is there a way to improve performance?
Marquinio
I'm guessing that after around 5000 records system is trying to GC some unused objects. I think in IE browser, if you open java console, it has commands to show memory usage etc. So may be you should try that. Alternatively, just define a main method in your applet and run it as java application and see if stops around 5000 records. May be that will give you some hint whether the issue is related to browser or the code as a whole. Let us know what you find.
prasrob
Ok I got this working last week. The problem was that the code was doing very heavy String manipulation. Code was doing things like str = str + "name1" + "name2" many times within nested loops. By switching to StringBuffer the processing time went from like 20 minutes to 15 seconds!!!Thanks for all your responses.
Marquinio
A: 

Remove the System.out.println() lines from the while loop. You're per saldo calling System.out.println() 30,000 times. That would add much overhead. Just place one before and one after the while loop if you want.

BalusC