FileDocCategorySizeDatePackage
IdleRemover.javaAPI DocJBoss 4.2.15795Fri Jul 13 21:01:18 BST 2007org.jboss.resource.connectionmanager

IdleRemover

public class IdleRemover extends Object
IdleRemover
author
David Jencks
author
Adrian Brock
version
$Revision: 57189 $

Fields Summary
private final Logger
log
private final Collection
pools
private long
interval
private long
next
private static final IdleRemover
remover
Constructors Summary
private IdleRemover()

      AccessController.doPrivileged(new PrivilegedAction()
      {
         public Object run()
         {
            Runnable runnable = new IdleRemoverRunnable();
            Thread removerThread = new Thread(runnable, "IdleRemover");
            removerThread.setDaemon(true);
            removerThread.start();
            return null;
         }
      });
   
Methods Summary
private voidinternalRegisterPool(InternalManagedConnectionPool mcp, long interval)

      log.debug("internalRegisterPool: registering pool with interval " + interval + " old interval: " + this.interval);
      synchronized (pools)
      {
         pools.add(mcp);
         if (interval > 1 && interval/2 < this.interval) 
         {
            this.interval = interval/2;
            long maybeNext = System.currentTimeMillis() + this.interval;
            if (next > maybeNext && maybeNext > 0) 
            {
               next = maybeNext;
               log.debug("internalRegisterPool: about to notify thread: old next: " + next + ", new next: " + maybeNext);
               pools.notify();
            }
         }
      }
   
private voidinternalUnregisterPool(InternalManagedConnectionPool mcp)

      synchronized (pools)
      {
         pools.remove(mcp);
         if (pools.size() == 0) 
         {
            log.debug("internalUnregisterPool: setting interval to Long.MAX_VALUE");
            interval = Long.MAX_VALUE;
         }
      }
   
public static voidregisterPool(InternalManagedConnectionPool mcp, long interval)


          
   
      remover.internalRegisterPool(mcp, interval);
   
private voidsetupContextClassLoader()
Change the context classloader to be where the idle remover was loaded from.

This avoids holding a reference to the caller's classloader which may be undeployed.

      // Could be null if loaded from system classloader
      final ClassLoader cl = IdleRemover.class.getClassLoader();
      if (cl == null)
         return;
      
      SecurityManager sm = System.getSecurityManager();
      if (sm == null)
         Thread.currentThread().setContextClassLoader(cl);
      
      AccessController.doPrivileged(new PrivilegedAction()
      {
         public Object run()
         {
            Thread.currentThread().setContextClassLoader(cl);
            return null;
         }
      });
   
public static voidunregisterPool(InternalManagedConnectionPool mcp)

      remover.internalUnregisterPool(mcp);
   
public static voidwaitForBackgroundThread()
For testing

      synchronized (remover.pools)
      {
         return;
      }