[prev in list] [next in list] [prev in thread] [next in thread]
List: jboss-cvs-commits
Subject: [jboss-cvs] jboss/src/main/org/jboss/ejb/plugins AbstractInstancePool.java
From: Bill Burke <patriot1burke () users ! sourceforge ! net>
Date: 2003-09-30 16:09:45
[Download RAW message or body]
User: patriot1burke
Date: 03/09/30 09:09:45
Modified: src/main/org/jboss/ejb/plugins Tag: Branch_3_2
AbstractInstancePool.java
Log:
Added MinimumSize for Pool so that it can be populated with an initial setting.
Can speed up performance if setXXXContext does a lot of synchronizations
Also, do not use a LinkedList for pool. Instead use a preallocated array. This is \
faster because it does not allocate a list Entry with every add
Revision Changes Path
No revision
No revision
1.28.2.13 +75 -33 jboss/src/main/org/jboss/ejb/plugins/AbstractInstancePool.java
Index: AbstractInstancePool.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/AbstractInstancePool.java,v
retrieving revision 1.28.2.12
retrieving revision 1.28.2.13
diff -u -r1.28.2.12 -r1.28.2.13
--- AbstractInstancePool.java 29 Sep 2003 04:27:37 -0000 1.28.2.12
+++ AbstractInstancePool.java 30 Sep 2003 16:09:45 -0000 1.28.2.13
@@ -28,13 +28,13 @@
* @author <a href="mailto:andreas.schaefer@madplanet.com">Andreas Schaefer</a>
* @author <a href="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>
* @author <a href="mailto:scott.stark@jboss.org">Scott Stark/a>
- * @version $Revision: 1.28.2.12 $
+ * @version $Revision: 1.28.2.13 $
*
* @jmx:mbean extends="org.jboss.system.ServiceMBean"
*/
public abstract class AbstractInstancePool
- extends ServiceMBeanSupport
- implements AbstractInstancePoolMBean, InstancePool, XmlLoadable
+ extends ServiceMBeanSupport
+ implements AbstractInstancePoolMBean, InstancePool, XmlLoadable
{
// Constants -----------------------------------------------------
@@ -54,9 +54,16 @@
protected int currentIndex = -1;
/** The maximum number of instances allowed in the pool */
protected int maxSize = 30;
+ /** The minimum size of the pool */
+ protected int minSize = 0;
/** determine if we reuse EnterpriseContext objects i.e. if we actually do \
pooling */ protected boolean reclaim = false;
+ protected volatile int overMin = 0;
+ protected volatile int overMax = 0;
+
+
+ protected boolean minSizeInitialized = false;
// Static --------------------------------------------------------
@@ -109,20 +116,20 @@
* @exception RemoteException
*/
public EnterpriseContext get()
- throws Exception
+ throws Exception
{
boolean trace = log.isTraceEnabled();
- if( trace )
- log.trace("Get instance "+this+"#"+(currentIndex + \
1)+"#"+getContainer().getBeanClass()); + if (trace)
+ log.trace("Get instance " + this + "#" + (currentIndex + 1) + "#" + \
getContainer().getBeanClass());
- if( strictMaxSize != null )
+ if (strictMaxSize != null)
{
// Block until an instance is available
boolean acquired = strictMaxSize.attempt(strictTimeout);
- if( trace )
- log.trace("Acquired("+acquired+") strictMaxSize semaphore, \
remaining="+strictMaxSize.permits());
- if( acquired == false )
- throw new EJBException("Failed to acquire the pool semaphore, \
strictTimeout="+strictTimeout); + if (trace)
+ log.trace("Acquired(" + acquired + ") strictMaxSize semaphore, \
remaining=" + strictMaxSize.permits()); + if (acquired == false)
+ throw new EJBException("Failed to acquire the pool semaphore, \
strictTimeout=" + strictTimeout); }
synchronized (pool)
@@ -131,10 +138,30 @@
{
EnterpriseContext ctx = pool[currentIndex];
pool[currentIndex--] = null;
+ overMin = 0;
return ctx;
}
}
+ if (!minSizeInitialized)
+ {
+ minSizeInitialized = true;
+ synchronized (pool)
+ {
+ for (int i = 0; i < minSize; i++)
+ {
+ pool[++currentIndex] = create(container.createBeanClassInstance());
+ }
+ }
+ }
+ /*
+ else if (minSize > 0 && ++overMin > overMax)
+ {
+ overMax = overMin;
+
+ log.warn("Went beyond min size for" + \
container.getBeanMetaData().getEjbName() + ": " + overMax); + }
+ */
// Pool is empty, create an instance
try
{
@@ -161,13 +188,13 @@
*/
public void free(EnterpriseContext ctx)
{
- if( log.isTraceEnabled() )
+ if (log.isTraceEnabled())
{
- String msg = (currentIndex + 1) + "/" + maxSize+" Free instance:"+this
- +"#"+ctx.getId()
- +"#"+ctx.getTransaction()
- +"#"+reclaim
- +"#"+getContainer().getBeanClass();
+ String msg = (currentIndex + 1) + "/" + maxSize + " Free instance:" + \
this + + "#" + ctx.getId()
+ + "#" + ctx.getTransaction()
+ + "#" + reclaim
+ + "#" + getContainer().getBeanClass();
log.trace(msg);
}
@@ -180,11 +207,12 @@
{
if (currentIndex + 1 < maxSize)
{
- pool[++currentIndex] = ctx;;
+ pool[++currentIndex] = ctx;
+ ;
} // end of if ()
- }
+ }
// If we block when maxSize instances are in use, invoke release on \
strictMaxSize
- if( strictMaxSize != null )
+ if (strictMaxSize != null)
strictMaxSize.release();
}
catch (Exception ignored)
@@ -194,17 +222,17 @@
public void discard(EnterpriseContext ctx)
{
- if( log.isTraceEnabled() )
+ if (log.isTraceEnabled())
{
- String msg = "Discard instance:"+this+"#"+ctx
- +"#"+ctx.getTransaction()
- +"#"+reclaim
- +"#"+getContainer().getBeanClass();
+ String msg = "Discard instance:" + this + "#" + ctx
+ + "#" + ctx.getTransaction()
+ + "#" + reclaim
+ + "#" + getContainer().getBeanClass();
log.trace(msg);
}
// If we block when maxSize instances are in use, invoke release on \
strictMaxSize
- if( strictMaxSize != null )
+ if (strictMaxSize != null)
strictMaxSize.release();
// Throw away, unsetContext()
@@ -214,7 +242,7 @@
}
catch (RemoteException e)
{
- if( log.isTraceEnabled() )
+ if (log.isTraceEnabled())
log.trace("Ctx.discard error", e);
}
}
@@ -235,15 +263,29 @@
throw new DeploymentException("Invalid MaximumSize value for instance \
pool configuration"); }
+ String minimumSize = \
MetaData.getElementContent(MetaData.getOptionalChild(element, "MinimumSize")); + \
if (minimumSize != null) + {
+ try
+ {
+ this.minSize = Integer.parseInt(minimumSize);
+ if (minSize < 1) minSizeInitialized = true; // don't pre-initialize
+ }
+ catch (NumberFormatException e)
+ {
+ throw new DeploymentException("Invalid MinimumSize value for instance \
pool configuration"); + }
+ }
+
// Get whether the pool will block when MaximumSize instances are active
String strictValue = \
MetaData.getElementContent(MetaData.getOptionalChild(element, "strictMaximumSize")); \
Boolean strictFlag = Boolean.valueOf(strictValue);
- if( strictFlag == Boolean.TRUE )
+ if (strictFlag == Boolean.TRUE)
this.strictMaxSize = new FIFOSemaphore(this.maxSize);
String delay = MetaData.getElementContent(MetaData.getOptionalChild(element, \
"strictTimeout")); try
{
- if( delay != null )
+ if (delay != null)
this.strictTimeout = Long.parseLong(delay);
}
catch (NumberFormatException e)
@@ -256,12 +298,12 @@
// Protected -----------------------------------------------------
protected abstract EnterpriseContext create(Object instance)
- throws Exception;
+ throws Exception;
protected void destroyService() throws Exception
{
- freeAll();
- this.container = null;
+ freeAll();
+ this.container = null;
}
// Private -------------------------------------------------------
@@ -271,7 +313,7 @@
*/
private void freeAll()
{
- synchronized(pool)
+ synchronized (pool)
{
for (int i = 0; i < currentIndex; i++)
{
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
jboss-cvs-commits mailing list
jboss-cvs-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-cvs-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic