From: fhanik Date: Fri, 14 Jul 2006 04:49:46 +0000 (+0000) Subject: Take advantage of Java 5 concurrent classes X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=350495912d37f88763207c95778f03a04d1dcd53;p=tomcat7.0 Take advantage of Java 5 concurrent classes git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@421806 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index 8301cbd6d..48278ae09 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -39,6 +39,7 @@ import org.apache.tomcat.jni.Poll; import org.apache.tomcat.jni.SSL; import org.apache.tomcat.jni.Status; import org.apache.tomcat.util.res.StringManager; +import java.util.concurrent.ConcurrentLinkedQueue; /** * NIO tailored thread pool, providing the following services: @@ -965,7 +966,7 @@ public class NioEndpoint { public class Poller implements Runnable { protected Selector selector; - protected LinkedList events = new LinkedList(); + protected ConcurrentLinkedQueue events = new ConcurrentLinkedQueue(); protected boolean close = false; protected long nextExpiration = 0;//optimize expiration handling @@ -1006,9 +1007,7 @@ public class NioEndpoint { } public void addEvent(Runnable event) { - synchronized (events) { - events.add(event); - } + events.add(event); selector.wakeup(); } @@ -1044,16 +1043,13 @@ public class NioEndpoint { } public void events() { - synchronized (events) { - Runnable r = null; - while ( (events.size() > 0) && (r = events.removeFirst()) != null ) { - try { - r.run(); - } catch ( Exception x ) { - log.error("",x); - } + Runnable r = null; + while ( (events.size() > 0) && (r = events.poll()) != null ) { + try { + r.run(); + } catch ( Exception x ) { + log.error("",x); } - events.clear(); } } @@ -1070,9 +1066,7 @@ public class NioEndpoint { } }; - synchronized (events) { - events.add(r); - } + events.add(r); selector.wakeup(); }