hi randy, thanks for your tips!

i think i found the reason for the growing memory consumption of my
servlets.

preconditions:
i use servlets to get data out and in a mysql database and generate
html pages with PrintWriter.print(...) statements.
my servlets often use:
...
Statement Stmt = C.createStatement();
ResultSet RS = Stmt.executeQuery("SELECT ..,..,.. from ..");
while (RS.next())
{
   //do something with data
   out.println(....);
}
...

on each request an instance of a servlet is created and the servlet
starts reading data out of the database and writes it in the
PrintWriter stream.
But what happens if the PrintWriter has no target (because the user
sends another request or more then one other requests)? I am not sure,
but it seems that the servlet tries to write to the PrintWriter stream
and has no success. the result is a growing amount of instances of a
servlet which try to write to a PrintWriter and have no success. and
it seems they keep try writing (and consuming memory) a long time ...

my solution is to check the error state of a Printwriter before
writing in it. so the code from above looks like this:
...
Statement Stmt = C.createStatement();
ResultSet RS = Stmt.executeQuery("SELECT ..,..,.. from ..");
while (RS.next())
{
   if (out.checkError()) break;
   //do something with data
   out.println(....);
}
...

for my application it seems to work, but i think there must be a better
way,
(why does the write statement throws an exception and the print
statement not?)
any ideas?

Gerd

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to