Summary: | StatementFinalizer closeInvoked is too slow for large batch jobs. | ||
---|---|---|---|
Product: | Tomcat Modules | Reporter: | kristo.kuuskull |
Component: | jdbc-pool | Assignee: | Tomcat Developers Mailing List <dev> |
Status: | RESOLVED FIXED | ||
Severity: | critical | ||
Priority: | P2 | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Hardware: | All | ||
OS: | All |
Description
kristo.kuuskull
2013-02-07 12:36:48 UTC
Ok, so if we used a linked list, it should be O(n) Can't we get keep ArrayList as it and instead of removing the object from the list (first line of StatementFinalizer.closeInvoked() method), just get that Statement reference and close that. At the end of loop when all Statements have been closed, we can just call clear() on the list. It will nullify all the references and those will GCed latter. Finding a particular entry in a linked list having millions of objects may also have some cost. With this code method closeInvoked() should look like public void closeInvoked() { for (WeakReference ws : this.statements) { Statement st = (Statement)ws.get(); if (st == null) continue; try { st.close(); } catch (Exception ignore) { if (log.isDebugEnabled()) log.debug("Unable to closed statement upon connection close.", ignore); } } this.statements.clear(); } Hope I am correct!!! (In reply to Rahul Singh from comment #3) > Can't we get keep ArrayList as it and instead of removing the object from > the list (first line of StatementFinalizer.closeInvoked() method), just get > that Statement reference and close that. Why do you specifically want to use an ArrayList? Why are you commenting on a bug that was closed almost one year ago? > At the end of loop when all Statements have been closed, we can just call > clear() on the list. It will nullify all the references and those will GCed > latter. > > Finding a particular entry in a linked list having millions of objects may > also have some cost. When do you need to index into the middle of the list? Have no love with ArrayList. Now noticed that it will always remove 0th index so that will not have any cost. I guessed this fix has not been released yet..sorry for commenting on FIXED thread. This fix was released long ago. It also has the advantage of being able to partially-process a list and remove those items processed. With ArrayList.clear, it's all or nothing. |