tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Einfeldt <ralph.einfe...@uptime-isc.de>
Subject AW: HELP: Memory Leak , requests are not worked off
Date Tue, 28 Nov 2000 11:37:24 GMT
Some of your problems can be created through your application.

If you have a session bean it will live as long as the session.
So if you issue 10000 requests from different sessions within the
lifetime of the first session, you will have 10000 beans and
sessions hanging around and the garbage collector, won't delete
the allocated objects because they are still referenced.


Also their might be some memory leak in tomcat and the jdbc driver.


Not cause for your problem but not good:
You are not calling cleanup() in the catch/finally clause ?

> -----Ursprüngliche Nachricht-----
> Von: Kai Müller [mailto:km@mediadom.de]
> Gesendet: Dienstag, 28. November 2000 11:32
> An: tomcat-user@jakarta.apache.org
> Betreff: 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
> 
> 
> 
> 
> 

Mime
View raw message