logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1125218 - /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
Date Fri, 20 May 2011 03:27:53 GMT
Author: rgoers
Date: Fri May 20 03:27:52 2011
New Revision: 1125218

URL: http://svn.apache.org/viewvc?rev=1125218&view=rev
Log:
Use a Semaphore instead of a Queue

Modified:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java?rev=1125218&r1=1125217&r2=1125218&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
Fri May 20 03:27:52 2011
@@ -31,6 +31,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -46,7 +47,7 @@ public class RollingFileManager extends 
     private long size;
     private long initialTime;
     private PatternProcessor processor;
-    private ArrayBlockingQueue<RollingFileManager> queue = new ArrayBlockingQueue<RollingFileManager>(1);
+    private final Semaphore semaphore = new Semaphore(1);
     private static int count = 0;
 
     private static ManagerFactory factory = new RollingFileManagerFactory();
@@ -63,7 +64,6 @@ public class RollingFileManager extends 
         this.size = size;
         this.initialTime = time;
         processor = new PatternProcessor(pattern);
-        queue.add(this);
     }
 
 
@@ -102,12 +102,8 @@ public class RollingFileManager extends 
     private boolean rollover(RolloverStrategy strategy) {
 
         try {
-            /* Block until the asynchronous operation is completed.
-             */
-            if (queue.take() == null) {
-                logger.error("Unable to acquire lock for rollover");
-                return false;
-            }
+            // Block until the asynchronous operation is completed.
+            semaphore.acquire();
         } catch (InterruptedException ie) {
             logger.error("Thread interrupted while attempting to check rollover", ie);
             return false;
@@ -138,8 +134,8 @@ public class RollingFileManager extends 
                     }
                 }
             } finally {
-                if (!success && queue.size() == 0) {
-                    queue.add(this);
+                if (!success && semaphore.availablePermits() == 0) {
+                    semaphore.release();
                 }
             }
             return true;
@@ -169,7 +165,7 @@ public class RollingFileManager extends 
             try {
                 return action.execute();
             } finally {
-                this.manager.queue.add(manager);
+                manager.semaphore.release();
             }
         }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message