FileDocCategorySizeDatePackage
Reaper.javaAPI DocGlassfish v2 API4450Fri May 04 22:33:18 BST 2007org.apache.tomcat.util.threads

Reaper

public class Reaper extends Thread
The reaper is a background thread with which ticks every minute and calls registered objects to allow reaping of old session data.
author
James Duncan Davidson [duncan@eng.sun.com]
author
Costin Manolache

Fields Summary
private static com.sun.org.apache.commons.logging.Log
log
private boolean
daemon
private long
interval
ThreadPoolRunnable[]
cbacks
Object[]
tdata
int
count
Object
lock
Adding and removing callbacks is synchronized
private boolean
running
Constructors Summary
public Reaper()


      
	if( daemon )
            this.setDaemon(true);
	this.setName("TomcatReaper");
    
public Reaper(String name)

        if( daemon )
            this.setDaemon(true);
	this.setName(name);
    
Methods Summary
public intaddCallback(ThreadPoolRunnable c, int interval)

	synchronized( lock ) {
	    cbacks[count]=c;
	    count++;
	    return count-1;
	}
    
public longgetDefaultIntervale()

        return interval;
    
public voidremoveCallback(int idx)

	synchronized( lock ) {
	    count--;
	    cbacks[idx]=cbacks[count];
	    cbacks[count]=null;
	}
    
public voidrun()

	while (running) {
	    if( !running) break;
	    try {
		this.sleep(interval);
	    } catch (InterruptedException ie) {
		// sometimes will happen
	    }

	    if( !running) break;
	    for( int i=0; i< count; i++ ) {
		ThreadPoolRunnable callB=cbacks[i];
		// it may be null if a callback is removed.
		//  I think the code is correct
		if( callB!= null ) {
		    callB.runIt( tdata[i] );
		}
		if( !running) break;
	    }
	}
    
public voidsetDefaultInterval(long t)


    // XXX Should be called 'interval' not defaultInterval

          
	interval=t;
    
public voidstartReaper()

	running=true;
	this.start();
    
public synchronized voidstopReaper()

	running=false;
        if (log.isDebugEnabled())
	    log.debug("Stop reaper ");
	this.interrupt(); // notify() doesn't stop sleep