abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r503951 - /incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/PoolManager.java
Date Tue, 06 Feb 2007 01:43:45 GMT
Author: jmsnell
Date: Mon Feb  5 17:43:44 2007
New Revision: 503951

URL: http://svn.apache.org/viewvc?view=rev&rev=503951
Log:
Enforce an upper limit to the object pool used by the server implementation.
This ensures that new objects can always be created (the pool will never run dry)
but limits the numbers of pooled objects that are ever retained in memory.

Modified:
    incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/PoolManager.java

Modified: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/PoolManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/PoolManager.java?view=diff&rev=503951&r1=503950&r2=503951
==============================================================================
--- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/PoolManager.java
(original)
+++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/PoolManager.java
Mon Feb  5 17:43:44 2007
@@ -19,9 +19,25 @@
 
 import java.util.Stack;
 
+/**
+ * Implements a simple pool manager.
+ * 
+ * An upper limit to the pool is set at 25 entries.  
+ * New items can always be created. 
+ */
 public abstract class PoolManager<T> {
 
-  private final Stack<T> pool = new Stack<T>();
+  private static final int SIZE = 25;
+  
+  private final Stack<T> pool = new Stack<T>() {
+    private static final long serialVersionUID = -6647024253014661104L;
+    @Override
+    public T push(T item) {
+      T obj = super.push(item);
+      if (this.size() > SIZE) this.removeElementAt(0);
+      return obj;
+    }
+  };
   
   protected synchronized T getInstance() {
     return (!pool.empty()) ? pool.pop() : internalNewInstance();



Mime
View raw message