[jboss-cvs] JBossCache/src/org/jboss/cache/loader ...

Elias Ross genman at noderunner.net
Fri Feb 9 14:21:28 EST 2007


  User: genman  
  Date: 07/02/09 14:21:28

  Modified:    src/org/jboss/cache/loader   AsynchCacheLoaderConfig.java
                        AsyncCacheLoader.java
  Log:
  JBCACHE-892 - Use more efficient "Queue.drainTo" call 
  
  Revision  Changes    Path
  1.3       +0 -20     JBossCache/src/org/jboss/cache/loader/AsynchCacheLoaderConfig.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AsynchCacheLoaderConfig.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/AsynchCacheLoaderConfig.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- AsynchCacheLoaderConfig.java	30 Dec 2006 19:48:44 -0000	1.2
  +++ AsynchCacheLoaderConfig.java	9 Feb 2007 19:21:28 -0000	1.3
  @@ -12,7 +12,6 @@
      private static final long serialVersionUID = 5038037589485991681L;
   
      private int batchSize = 100;
  -   private int pollWait = 100;
      private boolean returnOld = true;
      private int queueSize = 0;
      private boolean useAsyncPut = true;
  @@ -47,17 +46,6 @@
         this.batchSize = batchSize;
      }
   
  -   public int getPollWait()
  -   {
  -      return pollWait;
  -   }
  -
  -   public void setPollWait(int pollWait)
  -   {
  -      testImmutability("pollWait");
  -      this.pollWait = pollWait;
  -   }
  -
      public int getQueueSize()
      {
         return queueSize;
  @@ -106,12 +94,6 @@
            throw new IllegalArgumentException("Invalid size: " + batchSize);
         }
   
  -      s = props.getProperty("cache.async.pollWait");
  -      if (s != null)
  -      {
  -         pollWait = Integer.parseInt(s);
  -      }
  -
         s = props.getProperty("cache.async.returnOld");
         if (s != null)
         {
  @@ -137,7 +119,6 @@
         {
            AsynchCacheLoaderConfig other = (AsynchCacheLoaderConfig) obj;
            return (batchSize == other.batchSize)
  -                 && (pollWait == other.pollWait)
                    && (queueSize == other.queueSize)
                    && (returnOld == other.returnOld)
                    && (useAsyncPut == other.useAsyncPut);
  @@ -149,7 +130,6 @@
      {
         int result = hashCodeExcludingProperties();
         result = 31 * result + batchSize;
  -      result = 31 * result + pollWait;
         result = 31 * result + queueSize;
         result = 31 * result + (returnOld ? 0 : 1);
         result = 31 * result + (useAsyncPut ? 0 : 1);
  
  
  
  1.27      +12 -33    JBossCache/src/org/jboss/cache/loader/AsyncCacheLoader.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AsyncCacheLoader.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/AsyncCacheLoader.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -b -r1.26 -r1.27
  --- AsyncCacheLoader.java	2 Feb 2007 14:46:01 -0000	1.26
  +++ AsyncCacheLoader.java	9 Feb 2007 19:21:28 -0000	1.27
  @@ -18,7 +18,7 @@
   import java.util.List;
   import java.util.Map;
   import java.util.concurrent.BlockingQueue;
  -import java.util.concurrent.LinkedBlockingQueue;
  +import java.util.concurrent.ArrayBlockingQueue;
   import java.util.concurrent.TimeUnit;
   import java.util.concurrent.atomic.AtomicBoolean;
   import java.util.concurrent.atomic.AtomicInteger;
  @@ -85,7 +85,6 @@
   
      private static AtomicInteger threadId = new AtomicInteger(0);
   
  -
      /**
       * Default limit on entries to process asynchronously.
       */
  @@ -94,8 +93,7 @@
      private AsynchCacheLoaderConfig config;
      private AsyncProcessor processor;
      private AtomicBoolean stopped = new AtomicBoolean(true);
  -   private BlockingQueue<Modification> queue = new LinkedBlockingQueue(DEFAULT_QUEUE_SIZE);
  -
  +   private BlockingQueue<Modification> queue = new ArrayBlockingQueue<Modification>(DEFAULT_QUEUE_SIZE);
   
      public AsyncCacheLoader()
      {
  @@ -120,7 +118,7 @@
   
         if (config.getQueueSize() > 0)
         {
  -         queue = new LinkedBlockingQueue(config.getQueueSize());
  +         queue = new ArrayBlockingQueue<Modification>(config.getQueueSize());
         }
   
         super.setConfig(base);
  @@ -195,10 +193,10 @@
      {
         if (config.getUseAsyncPut())
         {
  -         Iterator i = modifications.iterator();
  +         Iterator<Modification> i = modifications.iterator();
            while (i.hasNext())
            {
  -            enqueue((Modification) i.next());
  +            enqueue(i.next());
            }
         }
         else
  @@ -266,7 +264,7 @@
         private Thread t;
   
         // Modifications to process as a single put
  -      private final List mods = new ArrayList(config.getBatchSize());
  +      private final List<Modification> mods = new ArrayList<Modification>(config.getBatchSize());
   
         public void start()
         {
  @@ -330,17 +328,12 @@
         private void run0() throws InterruptedException
         {
            log.trace("run0");
  -         Object o = queue.take();
  -         addTaken(o);
  -         while (mods.size() < config.getBatchSize())
  -         {
  -            o = queue.poll(config.getPollWait(), TimeUnit.MILLISECONDS);
  -            if (o == null)
  -            {
  -               break;
  -            }
  -            addTaken(o);
  +         int i = queue.drainTo(mods, config.getBatchSize());
  +         if (i == 0) {
  +            Modification m = queue.take();
  +            mods.add(m);
            }
  +         
            if (log.isTraceEnabled())
            {
               log.trace("put " + mods.size());
  @@ -349,19 +342,6 @@
            mods.clear();
         }
   
  -      private void addTaken(Object o)
  -      {
  -         if (o instanceof List)
  -         {
  -            mods.addAll((List) o);
  -         }
  -         else
  -         {
  -            Modification mod = (Modification) o;
  -            mods.add(mod);
  -         }
  -      }
  -
         private void put(List<Modification> mods)
         {
            try
  @@ -389,7 +369,6 @@
                 " processor=" + processor +
                 " stopped=" + stopped +
                 " batchSize=" + config.getBatchSize() +
  -              " pollWait=" + config.getPollWait() +
                 " returnOld=" + config.getReturnOld() +
                 " asyncPut=" + config.getUseAsyncPut() +
                 " queue.remainingCapacity()=" + queue.remainingCapacity() +
  
  
  



More information about the jboss-cvs-commits mailing list