Bug 23571

Summary: Thread count increases by 1 each time webapplication is restarted or reloaded.
Product: Xindice Reporter: Franqueli Mendez <franqueli_mendez>
Component: DB EngineAssignee: Xindice Developers <xindice-dev>
Status: CLOSED FIXED    
Severity: normal    
Priority: P3    
Version: cvs head (1.1)   
Target Milestone: ---   
Hardware: All   
OS: other   

Description Franqueli Mendez 2003-10-02 14:39:02 UTC
Each time the xindice webapp context is restarted or reloaded a new 
java.util.TimerThread is created that lives until the jvm is stopped. This 
eventually eats up all of the availiable memory and causes xindice to become 
unresponsive and throw OutOfMemory Errors.

I tracked down the creation of this thread to the 
org.apache.xindice.core.indexer.IndexManager class. Every time this class is 
loaded a static variable gets assigned a new java.util.Timer object which 
creates a thread.

    private static final Timer indexTimer = new Timer( true );

I fixed the problem on our application by adding the following method to the 
IndexManager class.

    protected void finalize(){

This is just a hack and will probably cause errors with indexing.

You can use the following to test see what is going on each time you restart a 
Runtime run = Runtime.getRuntime();

System.out.println("Thread count is " + Thread.activeCount());
System.out.println("Free memory " + run.freeMemory());
System.out.println("Total memory " + run.totalMemory());

I've tested this on Tomcat 4 running on WinXP Pro and on a Unix box and seen 
the same issue.
Comment 1 Vadim Gritsenko 2004-03-20 14:11:25 UTC
Suggested hack will cause indexing problem after just one collection is removed:
Timer is static, and each collection has IndexManager. Once collection is
removed, its IndexManager should get garbage collected (and finalized), and
cancelling the timer will break indexing in all other collections.

Proper solution should be to implement scheduling (cron) service; see also FIXME
note in IndexManager.
Comment 2 Vadim Gritsenko 2006-11-03 20:26:25 UTC