• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java-Mind-Teaser: Memory Problem with Tomcat/JSP

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hello, Java Gurus,
I have a JSP program which uses JavaBean to process data from
a database and outputs the result. I am running into
some memory problems. When I run the JSP program through
Internet Explorer, I usually monitor the memory used by
the process "java.exe". My memory problem is related to
the process "java.exe". Here is the detail:
Sometimes, because of the data returned from the database,
the JSP program will crash. When this happens, depending
on the data being processed, the process "java.exe" may
take quite large amount of memory (say 400k). I would
assume that since the JSP program has crached, garbage
collector will sneak out to mop the space once in a while.
But in my case, this never happens. If I rerun
the same JSP program again without restarting Tomcat,
then the memory taken by this process "java.exe" will start
to increase from where the previous crash left, i.e., 400k.
Of course, the same program will crash again, leaving
the memory taken by process "java.exe" to be about
doubling the previous amount, say 800k. This could
quickly clog the machine's memory and crash the webserver
(in my case, Tomcat).
Of course, if I stop Tomcat and then restart after each
jsp crashes, there will be no memory problem described
above.
My question to all you Java Jurus are:
(1) Why would this happen?
(2) How could I fix this, i.e., how could I ensure that
whenever a JSP program crash, the memory taken
by itself will be available for garbage collection,
or be collected by the system (without stopping Tomcat)?
I would appreciate any commects, suggestions, etc.
Sam

 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you say the JSP program crashed, what do you really mean? The servlet representing a JSP runs in the context of a server - Tomcat in this case - if the servlet throws an exception, and you the programmer don't handle it correctly, there could be all sorts of objects left in memory - Database connections, objects attached to a session, etc.
How are you handling exceptions?
Bill
 
Sam Zheng
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bill,
Thanks for the reply. I used the word "crash" in a very
loose way. The program doesn't actually CRASH. In fact
it just hangs in there. There is not exception issue here
since any potential exception issues have been handled.
The problem is "out of memory".
Specifically, the database is huge. Without taking
additional step to limit the size of returned data,
the JavaBean just issues a query and get whatever
returned data in the ResultSet. To give you an idea of
the size of this returned data, in one instance, it
returned 999,000 entries of data. I could run this
query once successfully and watch the memory taken
by process "java.exe" to grow to 55,000k (!). Run the
same program again and the memory will grow to 74,000k.
Run the same program the third time, then there will
be not output, nothing, the program hangs in there
and on Tomcat console, it gives you an error message,
something like "out of memory". So my problem is
not CRASH, it is out of memory.
I have taken precaution to make sure that my JSP page
has a page scope. I would assume that every time I
re-execute the same program, the memory taken by
previous execution will be available for garbage
collection, and will be garbage collected as JVM
detects the need of more memory. Apparently this
is not working in my case.
Any thoughts?
Thanks!
Sam
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What a monster of a database query!
You are going to have to figure out a way to take smaller chunks of the search result at a time. Unfortunately I don't do a whole lot of JDBC so I can't say how to do that.
Bill
 
reply
    Bookmark Topic Watch Topic
  • New Topic