User: lqd     
  Date: 02/02/22 03:14:32

  Modified:    src/main/org/jboss/pool Tag: Branch_2_4 PoolGCThread.java
  Log:
  - add logging
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.1.1.2.1 +116 -62   jbosspool/src/main/org/jboss/pool/PoolGCThread.java
  
  Index: PoolGCThread.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosspool/src/main/org/jboss/pool/PoolGCThread.java,v
  retrieving revision 1.1.1.1
  retrieving revision 1.1.1.1.2.1
  diff -u -r1.1.1.1 -r1.1.1.1.2.1
  --- PoolGCThread.java 15 May 2001 07:58:24 -0000      1.1.1.1
  +++ PoolGCThread.java 22 Feb 2002 11:14:31 -0000      1.1.1.1.2.1
  @@ -3,7 +3,10 @@
    */
   package org.jboss.pool;
   
  -import java.util.*;
  +import java.util.HashSet;
  +import java.util.Iterator;
  +
  +import org.jboss.logging.Logger;
   
   /**
    * Runs garbage collection on all available pools.  Only one GC thread is
  @@ -12,68 +15,119 @@
    * run on any pools which are "pretty close" to their requested time.
    *
    * @author Aaron Mulder ([EMAIL PROTECTED])
  + * @version $Revision: 1.1.1.1.2.1 $
    */
  -class PoolGCThread extends Thread {
  -    private HashSet pools = new HashSet();
  -
  -    PoolGCThread() {
  -        super("Minerve ObjectPool GC Thread");
  -        setDaemon(true);
  -    }
  -
  -    public void run() {
  -        while(true) {
  -            // Don't do anything while there's nothing to do
  -            waitForPools();
  -            // Figure out how long to sleep
  -            long delay = getDelay();
  -            // Sleep
  -            if(delay > 0l) {
  -                try {
  -                    sleep(delay);
  -                } catch(InterruptedException e) {}
  +class PoolGCThread extends Thread
  +{
  +   private HashSet pools = new HashSet();
  +     private static Logger log = Logger.getLogger( ObjectPool.class );
  +
  +   PoolGCThread()
  +   {
  +      super("Minerva ObjectPool GC Thread");
  +      setDaemon(true);
  +   }
  +
  +   public void run()
  +   {
  +      boolean debug = log.isDebugEnabled();
  +      while(true)
  +      {
  +         // Don't do anything while there's nothing to do
  +         waitForPools();
  +         if( debug )
  +            log.debug("gc thread waited for pools");
  +
  +         // Figure out how long to sleep
  +         long delay = getDelay();
  +         if( debug )
  +            log.debug("gc thread delay: " + delay);
  +
  +         // Sleep
  +         if(delay > 0l)
  +         {
  +            try
  +            {
  +               sleep(delay);
               }
  -            // Run garbage collection on eligible pools
  -            runGC();
  -        }
  -    }
  -
  -    private synchronized void waitForPools() {
  -        while(pools.size() == 0) {
  -            try {
  -                wait();
  -            } catch(InterruptedException e) {
  -            }
  -        }
  -    }
  +            catch(InterruptedException ignored) {}
  +         }
  +
  +         // Run garbage collection on eligible pools
  +         runGC();
  +      }
  +   }
  +
  +   private synchronized void waitForPools()
  +   {
  +      while(pools.size() == 0)
  +      {
  +         try
  +         {
  +            wait();
  +         }
  +         catch(InterruptedException ignored)
  +         {
  +            // Warning level seems appropriate; shouldn't really happen
  +            log.warn("waitForPools interrupted");
  +         }
  +      }
  +   }
  +
  +   private synchronized long getDelay()
  +   {
  +      long next = Long.MAX_VALUE;
  +      long now = System.currentTimeMillis();
  +      long current;
  +
  +      for(Iterator it = pools.iterator(); it.hasNext();)
  +      {
  +         ObjectPool pool = (ObjectPool)it.next();
  +         current = pool.getNextGCMillis(now);
  +         if(current < next)
  +            next = current;
  +      }
  +      return next >= 0l ? next : 0l;
  +   }
  +
  +   private synchronized void runGC()
  +   {
  +      boolean debug = log.isDebugEnabled();
  +
  +      if( debug )
  +         log.debug("GC thread running GC");
  +
  +      for(Iterator it = pools.iterator(); it.hasNext();)
  +      {
  +         ObjectPool pool = (ObjectPool)it.next();
  +
  +         if( debug )
  +            log.debug("GC Thread pool: " + pool.getName() + ", isTimeToGC(): " + 
pool.isTimeToGC() );
  +
  +         if(pool.isTimeToGC())
  +            pool.runGCandShrink();
  +      }
  +   }
  +
  +   synchronized void addPool(ObjectPool pool)
  +   {
  +      if( log.isDebugEnabled() )
  +         log.debug( "Adding pool: " + pool.getName() + ", GC enabled: " + 
pool.isGCEnabled() );
  +
  +      if(pool.isGCEnabled())
  +         pools.add(pool);
  +
  +      notify();
  +   }
  +
  +   synchronized void removePool(ObjectPool pool)
  +   {
  +      if( log.isDebugEnabled() )
  +         log.debug( "Removing pool: " + pool.getName() );
   
  -    private synchronized long getDelay() {
  -        long next = Long.MAX_VALUE;
  -        long now = System.currentTimeMillis();
  -        long current;
  -        for(Iterator it = pools.iterator(); it.hasNext();) {
  -            ObjectPool pool = (ObjectPool)it.next();
  -            current = pool.getNextGCMillis(now);
  -            if(current < next) next = current;
  -        }
  -        return next >= 0l ? next : 0l;
  -    }
  -
  -    private synchronized void runGC() {
  -        for(Iterator it = pools.iterator(); it.hasNext();) {
  -            ObjectPool pool = (ObjectPool)it.next();
  -            if(pool.isTimeToGC())
  -                pool.runGCandShrink();
  -        }
  -    }
  -
  -    synchronized void addPool(ObjectPool pool) {
  -        if(pool.isGCEnabled())
  -            pools.add(pool);
  -        notify();
  -    }
  -
  -    synchronized void removePool(ObjectPool pool) {
  -        pools.remove(pool);
  -    }
  +      pools.remove(pool);
  +   }
   }
  +/*
  +vim:tabstop=3:et:shiftwidth=3
  +*/
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to