donaldp 2002/10/17 19:29:30
Modified: pool/src/java/org/apache/avalon/excalibur/pool
DefaultPool.java
Log:
Make sure that pools never get corrupted if mutexs throw an exception.
Submitted By: Greg Steuck <[EMAIL PROTECTED]>
Revision Changes Path
1.2 +45 -32
jakarta-avalon-excalibur/pool/src/java/org/apache/avalon/excalibur/pool/DefaultPool.java
Index: DefaultPool.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/pool/src/java/org/apache/avalon/excalibur/pool/DefaultPool.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultPool.java 4 Apr 2002 05:09:04 -0000 1.1
+++ DefaultPool.java 18 Oct 2002 02:29:30 -0000 1.2
@@ -104,7 +104,7 @@
{
Poolable obj = null;
- if( false == m_initialized )
+ if( !m_initialized )
{
throw new IllegalStateException( "You cannot get a Poolable before the
pool is initialized" );
}
@@ -114,10 +114,9 @@
throw new IllegalStateException( "You cannot get a Poolable after the
pool is disposed" );
}
+ m_mutex.acquire();
try
{
- m_mutex.acquire();
-
if( m_ready.size() == 0 )
{
if( this instanceof Resizable )
@@ -130,7 +129,10 @@
}
else
{
- throw new Exception( "Could not create enough Components to
service your request." );
+ final String message =
+ "Could not create enough Components to service " +
+ "your request.";
+ throw new Exception( message );
}
}
else
@@ -147,7 +149,9 @@
if( getLogger().isDebugEnabled() )
{
- getLogger().debug( "Retrieving a " +
m_factory.getCreatedClass().getName() + " from the pool" );
+ final String message = "Retrieving a " +
+ m_factory.getCreatedClass().getName() + " from the pool";
+ getLogger().debug( message );
}
return obj;
}
@@ -159,9 +163,11 @@
public void put( final Poolable obj )
{
- if( false == m_initialized )
+ if( !m_initialized )
{
- throw new IllegalStateException( "You cannot get a Poolable before the
pool is initialized" );
+ final String message = "You cannot get a Poolable before " +
+ "the pool is initialized";
+ throw new IllegalStateException( message );
}
try
@@ -172,26 +178,35 @@
}
m_mutex.acquire();
-
- m_active.remove( m_active.indexOf( obj ) );
-
- if( getLogger().isDebugEnabled() )
+ try
{
- getLogger().debug( "Returning a " +
m_factory.getCreatedClass().getName() + " to the pool" );
- }
+ m_active.remove( m_active.indexOf( obj ) );
- if( m_disposed == false )
- {
- m_ready.add( obj );
+ if( getLogger().isDebugEnabled() )
+ {
+ final String message =
+ "Returning a " + m_factory.getCreatedClass().getName() +
+ " to the pool";
+ getLogger().debug( message );
+ }
+
+ if( m_disposed == false )
+ {
+ m_ready.add( obj );
- if( ( this.size() > m_max ) && ( this instanceof Resizable ) )
+ if( ( this.size() > m_max ) && ( this instanceof Resizable ) )
+ {
+ this.internalShrink( m_controller.shrink() );
+ }
+ }
+ else
{
- this.internalShrink( m_controller.shrink() );
+ this.removePoolable( obj );
}
}
- else
+ finally
{
- this.removePoolable( obj );
+ m_mutex.release();
}
}
catch( Exception e )
@@ -201,10 +216,6 @@
getLogger().warn( "Pool interrupted while waiting for lock.", e );
}
}
- finally
- {
- m_mutex.release();
- }
}
public final void dispose()
@@ -212,10 +223,16 @@
try
{
m_mutex.acquire();
-
- while( m_ready.size() > 0 )
+ try
{
- this.removePoolable( (Poolable)m_ready.remove() );
+ while( m_ready.size() > 0 )
+ {
+ this.removePoolable( (Poolable)m_ready.remove() );
+ }
+ }
+ finally
+ {
+ m_mutex.release();
}
}
catch( Exception e )
@@ -224,10 +241,6 @@
{
getLogger().warn( "Caught an exception disposing of pool", e );
}
- }
- finally
- {
- m_mutex.release();
}
this.m_disposed = true;
--
To unsubscribe, e-mail: <mailto:avalon-cvs-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@;jakarta.apache.org>