Hi,
It seems to happen exactly what you mention: You create a new Objects (at
least a Treemap) every time.
This will eat up your memory. For the Garbage Collection to be more efficent
you should release them after use by setting them to null.
Regards,
Andreas
> -----Original Message-----
> From: Kai M�ller [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, November 28, 2000 11:32 AM
> To: [EMAIL PROTECTED]
> Subject: HELP: Memory Leak , requests are not worked off
>
>
> Hello everybody,
>
> I have an urgent and difficult problem.
>
> My JSP reads data via JDBC from MySQL, more exactly: via an
> Accessor.class and a Database.class (both are unique in the
> application). I have one common persistent connection. The
> resultSet and
> statements are closed properly after each select. The results I write
> into new objects and fill a TreeMap of them which is in session scope
> (see also the code fragments).
>
> ---------- The problem --------------
>
> If I make 10.000 requests to the JSP (which reads everytime
> the TreeMap)
> directly one after another, the memory of the application
> grows, slowly,
> but permanently.
>
> This causes in the HTML-Output the following error:
>
> [...]
> java.lang.IllegalStateException: Response has already been committed
> at
> org.apache.tomcat.core.HttpServletResponseFacade.sendError(Htt
> pServletResponseFacade.java,
>
> Compiled Code)
> at
> org.apache.jasper.runtime.JspServlet.unknownException(JspServlet.java,
> Compiled Code)
> [...]
>
> In the Console-Output an OutOfMemoryError occurs. The 10.000 requests
> are not worked off to the end.
>
> ---------- The questions --------------
>
> 1. How does Tomcat handle quickly following requests?
> 2. Can you see if a request has been stopped (by pressing on reload or
> stop)?
> 3. Can you stop executing a started java process?
> 4. Is "Thread pooling" a solution? How does it work?
> 5. Why doesn't work the garbage collection in my case?
> 6. Can anybody help me???
>
> Thank you very much.
>
> Kai M�ller
>
> ---------- Code fragments -----------
>
> ---------- JSP fragment -------------
> ...
> <%-- initialize myTreeMap in head of JSP --%>
> <jsp:useBean id="myTreeMap" class="Accessor" scope = "session">
> </jsp:useBean>
> ...
> <%-- use myTreeMap in JSP: handler reads data from database --%>
> <% myTreeMap.readTreeMap(application);
> ... use myTreeMap ...
> %>
>
> ---------- Accessor fragment -------------
> ...
> private TreeMap theMap;
> private DatabaseBean myBean;
> ...
> public Accessor(ServletContext application) {
> theMap = new TreeMap();
> myBean = new DatabaseBean();
>
> }
> ...
> public synchronized TreeMap readTreeMap (ServletContext
> application) {
>
> theMap.clear();
> try {
> myBean.select(); // creates SQL-Statement and resultSet
> List theResultList = myBean.buildResultList();
> for(Iterator it=theResultList.iterator();it.hasNext();) {
> MyObject myObject = (MyObject) it.next() ;
> theMap.put(new Integer(myObject.getObjectid()),myObject) ;
> }
> myBean.cleanup() ;
> } catch (Exception e ) {
> }
> return theMap ;
> }
>
> ---------- DatabaseBean fragment -------------
> ...
> private ResultSet rs;
> private Statement st = null;
> private ArrayList arraylist = new ArrayList();
> private int objectid, objectcontent;
> ...
> public void select() {
> try {
> if (rs != null) { rs.close(); rs = null;}
> if (st != null) { st.close(); st = null;}
> Connection tmp = PersistentConnection.getConnection();
> st = tmp.createStatement();
> String query = "SELECT * FROM databaseTable;";
> rs = st.executeQuery(query);
> } catch (Exception e) {
> }
> }
> ...
> // Create an object out of a db row for the Object type
> // and build a result List from it
> public List buildResultList() {
> arraylist.clear();
> if (rs != null && next()) {
> do {
> arraylist.add(new MyObject(objectid,objectContent));
> } while(next());
> }
> return arraylist;
> }
>
> public void cleanup() {
> try {
> if (rs != null) rs.close();
> if (st != null) st.close();
> } catch (Exception e) {
> System.out.println("No Cleanup possible in DatabaseBean");
> }
> }
>
> ---------- End fragments -------------
>
>
>
>
> Mediadom audiovisuelle Medien GmbH
> Merheimer Str. 151
> D-50733 Koeln
>
>
>
>