directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r429987 - in /directory/trunks/mina/core/src/main/java/org/apache/mina/common: PooledThreadModel.java support/BaseIoServiceConfig.java
Date Wed, 09 Aug 2006 08:08:32 GMT
Author: trustin
Date: Wed Aug  9 01:08:32 2006
New Revision: 429987

URL: http://svn.apache.org/viewvc?rev=429987&view=rev
Log:
Fixed issue: DIRMINA-231 (SocketConnector thread leak)
* PooledThreadModel now manages the instances of PooledThreadModels, and therefore the number
of PooledThreadModel per service never exceeds 1.

Modified:
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/PooledThreadModel.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoServiceConfig.java

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/PooledThreadModel.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/PooledThreadModel.java?rev=429987&r1=429986&r2=429987&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/PooledThreadModel.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/PooledThreadModel.java
Wed Aug  9 01:08:32 2006
@@ -18,6 +18,9 @@
  */
 package org.apache.mina.common;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.mina.filter.thread.ThreadPool;
 import org.apache.mina.filter.thread.ThreadPoolFilter;
 
@@ -46,26 +49,46 @@
      */
     public static final int DEFAULT_KEEP_ALIVE_TIME = ThreadPool.DEFAULT_KEEP_ALIVE_TIME;
     
-    private static int id = 1;
+    /**
+     * Maps a service name to a PooledThreadModel instance.
+     * Without this map, we might create extremely many thread pools that leads the system
to
+     * coma. */
+    private static final Map service2model = new HashMap();
     
-    private final ThreadPoolFilter filter = new ThreadPoolFilter();
-
-    public PooledThreadModel()
+    /**
+     * Returns a {@link PooledThreadModel} instance for the specified <tt>serviceName</tt>.
+     * @param serviceName the name of the service that needs thread pooling
+     */
+    public static PooledThreadModel getInstance( String serviceName )
     {
-        this( "AnonymousIoService-" + id++, DEFAULT_MAXIMUM_POOL_SIZE );
+    	if( serviceName == null )
+    	{
+    		throw new NullPointerException( "serviceName" );
+    	}
+
+    	PooledThreadModel model;
+    	synchronized( service2model )
+    	{
+    		model = ( PooledThreadModel ) service2model.get( serviceName );
+    		if( model == null )
+    		{
+    			model = new PooledThreadModel( serviceName );
+    			service2model.put( serviceName, model );
+    		}
+    	}
+    	
+    	return model;
     }
     
-    public PooledThreadModel( int maxThreads )
-    {
-        this( "AnonymousIoService-" + id++, maxThreads );
-    }
+    private final ThreadPoolFilter filter = new ThreadPoolFilter();
+    private final IoFilter proxy = new ReferenceCountingIoFilter( filter );
 
-    public PooledThreadModel( String threadNamePrefix )
+    private PooledThreadModel( String threadNamePrefix )
     {
         this( threadNamePrefix, DEFAULT_MAXIMUM_POOL_SIZE );
     }
 
-    public PooledThreadModel( String threadNamePrefix, int maxThreads )
+    private PooledThreadModel( String threadNamePrefix, int maxThreads )
     {
         setMaximumPoolSize( maxThreads );
         setThreadNamePrefix( threadNamePrefix );
@@ -103,6 +126,6 @@
 
     public void buildFilterChain( IoFilterChain chain ) throws Exception
     {
-        chain.addFirst( PooledThreadModel.class.getName(), filter );
+        chain.addFirst( PooledThreadModel.class.getName(), proxy );
     }
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoServiceConfig.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoServiceConfig.java?rev=429987&r1=429986&r2=429987&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoServiceConfig.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoServiceConfig.java
Wed Aug  9 01:08:32 2006
@@ -39,7 +39,7 @@
      */
     private IoFilterChainBuilder filterChainBuilder = new DefaultIoFilterChainBuilder();
     
-    private final ThreadModel defaultThreadModel = new PooledThreadModel();
+    private final ThreadModel defaultThreadModel = PooledThreadModel.getInstance("AnonymousIoService");
     /**
      * Current thread model.
      */



Mime
View raw message