directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r239282 - in /directory/network: branches/0.7/src/java/org/apache/mina/util/BaseThreadPool.java trunk/src/java/org/apache/mina/filter/ThreadPoolFilter.java trunk/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java
Date Tue, 23 Aug 2005 01:01:45 GMT
Author: trustin
Date: Mon Aug 22 18:01:39 2005
New Revision: 239282

URL: http://svn.apache.org/viewcvs?rev=239282&view=rev
Log:
Possible fix for DIRMINA-79 - The number of ThreadPoolFilter threads sometimes becomes 0.
* Fixed a bug that the thread can die when interrupted in Worker.waitForPromotion() and Worker.fetchBuffer()


Modified:
    directory/network/branches/0.7/src/java/org/apache/mina/util/BaseThreadPool.java
    directory/network/trunk/src/java/org/apache/mina/filter/ThreadPoolFilter.java
    directory/network/trunk/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java

Modified: directory/network/branches/0.7/src/java/org/apache/mina/util/BaseThreadPool.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/0.7/src/java/org/apache/mina/util/BaseThreadPool.java?rev=239282&r1=239281&r2=239282&view=diff
==============================================================================
--- directory/network/branches/0.7/src/java/org/apache/mina/util/BaseThreadPool.java (original)
+++ directory/network/branches/0.7/src/java/org/apache/mina/util/BaseThreadPool.java Mon Aug
22 18:01:39 2005
@@ -319,7 +319,14 @@
 
                 if( buf == null )
                 {
-                    break;
+                    if( shuttingDown )
+                    {
+                        break;
+                    }
+                    else
+                    {
+                        continue;
+                    }
                 }
 
                 processEvents( buf );
@@ -429,25 +436,41 @@
         {
             final Object promotionLock = this.promotionLock;
 
+            final long startTime = System.currentTimeMillis();
+            long currentTime = startTime;
+            
             synchronized( promotionLock )
             {
-                if( this != leader )
+                while( this != leader )
                 {
+                    // Calculate remaining keep-alive time
+                    int keepAliveTime = getKeepAliveTime();
+                    if( keepAliveTime > 0 )
+                    {
+                        keepAliveTime -= ( currentTime - startTime );
+                    }
+                    else
+                    {
+                        keepAliveTime = Integer.MAX_VALUE;
+                    }
+                    
+                    // Break the loop if there's no remaining keep-alive time.
+                    if( keepAliveTime <= 0 )
+                    {
+                        break;
+                    }
+
+                    // Wait for promotion
                     try
                     {
-                        int keepAliveTime = getKeepAliveTime();
-                        if( keepAliveTime > 0 )
-                        {
-                            promotionLock.wait( keepAliveTime );
-                        }
-                        else
-                        {
-                            promotionLock.wait();
-                        }
+                        promotionLock.wait( keepAliveTime );
                     }
                     catch( InterruptedException e )
                     {
                     }
+
+                    // Update currentTime for the next iteration
+                    currentTime = System.currentTimeMillis();
                 }
 
                 boolean timeToLead = this == leader;

Modified: directory/network/trunk/src/java/org/apache/mina/filter/ThreadPoolFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/ThreadPoolFilter.java?rev=239282&r1=239281&r2=239282&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/ThreadPoolFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/ThreadPoolFilter.java Mon Aug
22 18:01:39 2005
@@ -285,7 +285,14 @@
 
                 if( buf == null )
                 {
-                    break;
+                    if( shuttingDown )
+                    {
+                        break;
+                    }
+                    else
+                    {
+                        continue;
+                    }
                 }
 
                 processEvents( buf );
@@ -395,25 +402,41 @@
         {
             final Object promotionLock = this.promotionLock;
 
+            long startTime = System.currentTimeMillis();
+            long currentTime = System.currentTimeMillis();
+            
             synchronized( promotionLock )
             {
-                if( this != leader )
+                while( this != leader )
                 {
+                    // Calculate remaining keep-alive time
+                    int keepAliveTime = getKeepAliveTime();
+                    if( keepAliveTime > 0 )
+                    {
+                        keepAliveTime -= ( currentTime - startTime );
+                    }
+                    else
+                    {
+                        keepAliveTime = Integer.MAX_VALUE;
+                    }
+                    
+                    // Break the loop if there's no remaining keep-alive time.
+                    if( keepAliveTime <= 0 )
+                    {
+                        break;
+                    }
+
+                    // Wait for promotion
                     try
                     {
-                        int keepAliveTime = getKeepAliveTime();
-                        if( keepAliveTime > 0 )
-                        {
-                            promotionLock.wait( keepAliveTime );
-                        }
-                        else
-                        {
-                            promotionLock.wait();
-                        }
+                        promotionLock.wait( keepAliveTime );
                     }
                     catch( InterruptedException e )
                     {
                     }
+
+                    // Update currentTime for the next iteration
+                    currentTime = System.currentTimeMillis();
                 }
 
                 boolean timeToLead = this == leader;

Modified: directory/network/trunk/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java?rev=239282&r1=239281&r2=239282&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java
(original)
+++ directory/network/trunk/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java
Mon Aug 22 18:01:39 2005
@@ -36,6 +36,7 @@
     public void tearDown()
     {
         filter.filterRemoved( FILTER_PARENT );
+        Assert.assertEquals( 0, filter.getPoolSize() );
         filter = null;
     }
     
@@ -57,6 +58,7 @@
         };
         final int end = sessions.length - 1;
         final ThreadPoolFilter filter = this.filter;
+        filter.setKeepAliveTime( 3000 );
         
         for( int i = 0; i < 1000000 ; i++ )
         {
@@ -72,6 +74,10 @@
                 throw nextFilter.throwable;
             }
         }
+        
+        Thread.sleep( 3500 );
+        
+        Assert.assertEquals( 1, filter.getPoolSize() );
     }
     
     private static class EventOrderCounter extends BaseIoSession



Mime
View raw message