Bug 23571 - Thread count increases by 1 each time webapplication is restarted or reloaded.
Summary: Thread count increases by 1 each time webapplication is restarted or reloaded.
Status: CLOSED FIXED
Alias: None
Product: Xindice
Classification: Unclassified
Component: DB Engine (show other bugs)
Version: cvs head (1.1)
Hardware: All other
: P3 normal
Target Milestone: ---
Assignee: Xindice Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-02 14:39 UTC by Franqueli Mendez
Modified: 2006-11-03 20:26 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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(){
        indexTimer.cancel();
    }

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 
context.
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
fixed