User: d_jencks
Date: 01/09/08 12:32:22
Modified: src/main/org/jboss/pool ObjectPool.java PoolGCThread.java
PoolParameters.java
Log:
Reorganized connector packaging under connector (from pool), made jca stuff into a
sar, made default hypsersonic DefaultDS into hsql-default-service.xml, and made
jbossmq into jbossmq-service.xml
Revision Changes Path
1.5 +57 -41 jbosspool/src/main/org/jboss/pool/ObjectPool.java
Index: ObjectPool.java
===================================================================
RCS file: /cvsroot/jboss/jbosspool/src/main/org/jboss/pool/ObjectPool.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ObjectPool.java 2001/08/19 04:55:29 1.4
+++ ObjectPool.java 2001/09/08 19:32:22 1.5
@@ -47,18 +47,18 @@
private int minSize = 0;
private int maxSize = 0;
private boolean idleTimeout = false;
- private boolean runGC = false;
+ private boolean GCEnabled = false;
private float maxIdleShrinkPercent = 1.0f;
// don't replace idle connections that timeout
private long idleTimeoutMillis = 1800000l;
// must be idle in pool for 30 minutes
private long gcMinIdleMillis = 1200000l;
// must be unused by client for 20 minutes
- private long gcIntervalMillis = 120000l;
+ private long cleanupIntervalMillis = 120000l;
// shrink & gc every 2 minutes
- private long lastGC = System.currentTimeMillis();
+ private long lastCleanup = System.currentTimeMillis();
private boolean blocking = true;
- private int blockingTimeout = -1;
+ private long blockingTimeout = -1;
// meaning forever
private boolean trackLastUsed = false;
private boolean invalidateOnError = false;
@@ -66,6 +66,7 @@
private final static String INITIALIZED = "Pool already initialized!";
private final static PoolGCThread collector = new PoolGCThread();
+
/**
* Creates a new pool. It cannot be used until you specify a name and object
* factory or bean class, and initialize it.
@@ -259,7 +260,7 @@
if ( objects != null ) {
throw new IllegalStateException( INITIALIZED );
}
- runGC = enabled;
+ GCEnabled = enabled;
}
/**
@@ -351,7 +352,7 @@
if ( objects != null ) {
throw new IllegalStateException( INITIALIZED );
}
- gcIntervalMillis = millis;
+ cleanupIntervalMillis = millis;
}
/**
@@ -378,7 +379,7 @@
*
* @param blockingTimeout The new BlockingTimeout value
*/
- public void setBlockingTimeout( int blockingTimeout ) {
+ public void setBlockingTimeout( long blockingTimeout ) {
this.blockingTimeout = blockingTimeout;
}
@@ -502,7 +503,12 @@
* @see #setGCEnabled
*/
public boolean isGCEnabled() {
- return runGC;
+ return GCEnabled;
+ }
+
+
+ public boolean isCleanupEnabled() {
+ return isGCEnabled() || isIdleTimeoutEnabled();
}
/**
@@ -543,7 +549,7 @@
* @see #setGCInterval
*/
public long getGCInterval() {
- return gcIntervalMillis;
+ return cleanupIntervalMillis;
}
/**
@@ -562,7 +568,7 @@
*
* @return The BlockingTimeout value
*/
- public int getBlockingTimeout() {
+ public long getBlockingTimeout() {
return this.blockingTimeout;
}
@@ -607,6 +613,7 @@
* @see #setBlocking
*/
public Object getObject( Object parameters ) {
+
if ( objects == null ) {
throw new IllegalStateException( "Tried to use pool before it was
Initialized or after it was ShutDown!" );
}
@@ -619,6 +626,9 @@
// return the same result. This is unusual.
boolean shouldBlock = blocking;
+ long ourTimeout = blockingTimeout;
+ long end = System.currentTimeMillis() + blockingTimeout;
+
while ( true ) {
Iterator it = objects.values().iterator();
while ( it.hasNext() ) {
@@ -634,8 +644,8 @@
if ( result instanceof PooledObject ) {
( ( PooledObject )result ).addPoolEventListener( this );
}
- if ( log.isTraceEnabled() ) {
- log.trace( "Pool " + this + " gave out pooled object: " +
result );
+ if ( log.isDebugEnabled() ) {
+ log.debug( "Pool " + this + " gave out pooled object: " +
result );
}
return result;
} catch ( ConcurrentModificationException e ) {
@@ -660,15 +670,20 @@
}
if ( shouldBlock ) {
- if ( log.isTraceEnabled() ) {
- log.trace( "Pool " + this + " waiting for a free object" );
+ if ( log.isDebugEnabled() ) {
+ log.debug( "Pool " + this + " waiting for a free object" );
}
synchronized ( this ) {
try {
- if ( blockingTimeout > 0 ) {
- wait( blockingTimeout );
- shouldBlock = false;
- //don't wait again
+ if ( ourTimeout > 0 ) {
+ wait( ourTimeout );
+ ourTimeout = end - System.currentTimeMillis();
+ if ( log.isDebugEnabled() ) {
+ log.debug( "Pool waiting for (millis): " + ourTimeout );
+ }
+ if (ourTimeout <= 0) {
+ shouldBlock = false; //don't wait again
+ }
} else {
wait();
}
@@ -679,8 +694,8 @@
break;
}
}
- if ( log.isTraceEnabled() ) {
- log.trace( "Pool " + this + " couldn't find an object to return!" );
+ if ( log.isDebugEnabled() ) {
+ log.debug( "Pool " + this + " couldn't find an object to return!" );
}
return result;
}
@@ -704,7 +719,7 @@
deadObjects = new HashSet();
objects = new HashMap();
factory.poolStarted( this );
- lastGC = System.currentTimeMillis();
+ lastCleanup = System.currentTimeMillis();
int max = maxSize <= 0 ? minSize : Math.min( minSize, maxSize );
for ( int i = 0; i < max; i++ ) {
createNewObject( null, false );
@@ -816,11 +831,11 @@
removed = false;
}
}
- if ( log.isTraceEnabled() ) {
+ if ( log.isDebugEnabled() ) {
if ( removed ) {
- log.trace( "Pool " + this + " destroyed object " + object + "." );
+ log.debug( "Pool " + this + " destroyed object " + object + "." );
} else {
- log.trace( "Pool " + this + " returned object " + object + " to the
pool." );
+ log.debug( "Pool " + this + " returned object " + object + " to the
pool." );
}
}
if ( blocking ) {
@@ -876,21 +891,22 @@
setLastUsed( evt.getSource() );
}
- long getNextGCMillis( long now ) {
- if ( !runGC ) {
+ long getNextCleanupMillis( long now ) {
+ if ( !isCleanupEnabled() ) {
return Long.MAX_VALUE;
}
- return lastGC + gcIntervalMillis - now;
+ return lastCleanup + cleanupIntervalMillis - now;
}
// Allow GC if we're within 10% of the desired interval
- boolean isTimeToGC() {
+ boolean isTimeToCleanup() {
return System.currentTimeMillis() >=
- lastGC + Math.round( ( float )gcIntervalMillis * 0.9f );
+ lastCleanup + Math.round( ( float )cleanupIntervalMillis * 0.9f );
}
- void runGCandShrink() {
- if ( runGC ) {
+ void runCleanupandShrink() {
+ log.warn("running gc for pool");
+ if ( isCleanupEnabled() ) {
// Garbage collection - return any object that's been out too long with no
use
Iterator it = new HashSet( objects.values() ).iterator();
while ( it.hasNext() ) {
@@ -942,7 +958,7 @@
}
}
}
- lastGC = System.currentTimeMillis();
+ lastCleanup = System.currentTimeMillis();
}
private int getUsedCount() {
@@ -983,7 +999,7 @@
*/
private Object createNewObject( Object parameters, boolean forImmediateUse ) {
Object ob = null;
- boolean traceEnabled = log.isTraceEnabled();
+ boolean debugEnabled = log.isDebugEnabled();
// Serialize creating new objects
synchronized ( resizeLock ) {
// Don't let 2 threads add at the same time
@@ -1002,24 +1018,24 @@
if ( result instanceof PooledObject ) {
( ( PooledObject )result ).addPoolEventListener( this );
}
- if ( traceEnabled ) {
- log.trace( "Pool " + poolName + " gave out new object: " +
result );
+ if ( debugEnabled ) {
+ log.debug( "Pool " + poolName + " gave out new object: " +
result );
}
ob = result;
} else {
- if ( traceEnabled ) {
- log.trace( "Pool " + poolName + " created a new object: " + ob
);
+ if ( debugEnabled ) {
+ log.debug( "Pool " + poolName + " created a new object: " + ob
);
}
}
objects = newMap;
} else {
- if ( traceEnabled ) {
- log.trace( "Pool " + poolName + " factory " + factory + " unable
to create new object!" );
+ if ( debugEnabled ) {
+ log.debug( "Pool " + poolName + " factory " + factory + " unable
to create new object!" );
}
}
} else {
- if ( traceEnabled ) {
- log.trace( "Pool " + poolName + " is full (" + objects.size() + "/"
+ maxSize + ")!" );
+ if ( debugEnabled ) {
+ log.debug( "Pool " + poolName + " is full (" + objects.size() + "/"
+ maxSize + ")!" );
}
}
}
1.3 +17 -6 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PoolGCThread.java 2001/08/19 04:55:30 1.2
+++ PoolGCThread.java 2001/09/08 19:32:22 1.3
@@ -6,6 +6,8 @@
import java.util.HashSet;
import java.util.Iterator;
+import org.jboss.logging.log4j.JBossCategory;
+
/**
* Runs garbage collection on all available pools. Only one GC thread is
* created, no matter how many pools there are - it just tries to calculate the
@@ -13,22 +15,27 @@
* on any pools which are "pretty close" to their requested time.
*
* @author Aaron Mulder ([EMAIL PROTECTED])
- * @created August 18, 2001
*/
class PoolGCThread extends Thread {
+
+ static JBossCategory category =
(JBossCategory)JBossCategory.getInstance(PoolGCThread.class.getName());
+
private HashSet pools = new HashSet();
PoolGCThread() {
- super( "Minerve ObjectPool GC Thread" );
+ super( "Minerva ObjectPool GC Thread" );
setDaemon( true );
}
public void run() {
+ category.debug("Started gc thread");
while ( true ) {
// Don't do anything while there's nothing to do
waitForPools();
+ category.debug("gc thread waited for pools");
// Figure out how long to sleep
long delay = getDelay();
+ category.debug("gc thread delay: " + delay);
// Sleep
if ( delay > 0l ) {
try {
@@ -42,7 +49,8 @@
}
synchronized void addPool( ObjectPool pool ) {
- if ( pool.isGCEnabled() ) {
+ category.debug("Adding pool: " + pool.getName() + ", Cleanup enabled: " +
pool.isCleanupEnabled());
+ if ( pool.isCleanupEnabled() ) {
pools.add( pool );
}
notify();
@@ -58,7 +66,7 @@
long current;
for ( Iterator it = pools.iterator(); it.hasNext(); ) {
ObjectPool pool = ( ObjectPool )it.next();
- current = pool.getNextGCMillis( now );
+ current = pool.getNextCleanupMillis( now );
if ( current < next ) {
next = current;
}
@@ -71,15 +79,18 @@
try {
wait();
} catch ( InterruptedException e ) {
+ category.debug("waitForPools interrupted");
}
}
}
private synchronized void runGC() {
+ category.debug("gc thread running gc");
for ( Iterator it = pools.iterator(); it.hasNext(); ) {
ObjectPool pool = ( ObjectPool )it.next();
- if ( pool.isTimeToGC() ) {
- pool.runGCandShrink();
+ category.debug("gc thread pool: " + pool.getName() + " isTimeToCleanup()"
+ pool.isTimeToCleanup());
+ if ( pool.isTimeToCleanup() ) {
+ pool.runCleanupandShrink();
}
}
}
1.3 +2 -0 jbosspool/src/main/org/jboss/pool/PoolParameters.java
Index: PoolParameters.java
===================================================================
RCS file: /cvsroot/jboss/jbosspool/src/main/org/jboss/pool/PoolParameters.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PoolParameters.java 2001/08/19 04:55:30 1.2
+++ PoolParameters.java 2001/09/08 19:32:22 1.3
@@ -18,6 +18,7 @@
public int minSize = 0;
public int maxSize = 0;
public boolean blocking = true;
+ public long blockingTimeoutMillis = -1; //never times out on blocking
public boolean gcEnabled = false;
public boolean idleTimeoutEnabled = false;
public boolean invalidateOnError = false;
@@ -29,6 +30,7 @@
public final static String MIN_SIZE_KEY = "MinSize";
public final static String MAX_SIZE_KEY = "MaxSize";
public final static String BLOCKING_KEY = "Blocking";
+ public final static String BLOCKING_TIMEOUT_MS_KEY = "BlockingTimeoutMillis";
public final static String GC_ENABLED_KEY = "GCEnabled";
public final static String IDLE_TIMEOUT_ENABLED_KEY = "IdleTimeoutEnabled";
public final static String INVALIDATE_ON_ERROR_KEY = "InvalidateOnError";
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development