You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2015/10/25 10:44:04 UTC

svn commit: r1710420 - /qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/transport/SelectorThread.java

Author: kwall
Date: Sun Oct 25 09:44:04 2015
New Revision: 1710420

URL: http://svn.apache.org/viewvc?rev=1710420&view=rev
Log:
QPID-6797 : Have selection task use Collections#emptyList whenever possible

Save unnecessary construction/garbage for both list and iterator during selector event loop

Modified:
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/transport/SelectorThread.java

Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/transport/SelectorThread.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/transport/SelectorThread.java?rev=1710420&r1=1710419&r2=1710420&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/transport/SelectorThread.java (original)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/transport/SelectorThread.java Sun Oct 25 09:44:04 2015
@@ -26,6 +26,7 @@ import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
 import java.nio.channels.ServerSocketChannel;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -111,11 +112,16 @@ class SelectorThread extends Thread
 
         private List<NonBlockingConnection> processUnscheduledConnections()
         {
+            _nextTimeout = Integer.MAX_VALUE;
+            if (getUnscheduledConnections().isEmpty())
+            {
+                return Collections.emptyList();
+            }
+
             List<NonBlockingConnection> toBeScheduled = new ArrayList<>();
 
             long currentTime = System.currentTimeMillis();
             Iterator<NonBlockingConnection> iterator = getUnscheduledConnections().iterator();
-            _nextTimeout = Integer.MAX_VALUE;
             while (iterator.hasNext())
             {
                 NonBlockingConnection connection = iterator.next();
@@ -147,9 +153,13 @@ class SelectorThread extends Thread
 
         private List<NonBlockingConnection> processSelectionKeys()
         {
-            List<NonBlockingConnection> toBeScheduled = new ArrayList<>();
-
             Set<SelectionKey> selectionKeys = _selector.selectedKeys();
+            if (selectionKeys.isEmpty())
+            {
+                return Collections.emptyList();
+            }
+
+            List<NonBlockingConnection> toBeScheduled = new ArrayList<>();
             for (SelectionKey key : selectionKeys)
             {
                 if(key.isAcceptable())
@@ -185,6 +195,10 @@ class SelectorThread extends Thread
 
         private List<NonBlockingConnection> reregisterUnregisteredConnections()
         {
+            if (getUnregisteredConnections().isEmpty())
+            {
+                return Collections.emptyList();
+            }
             List<NonBlockingConnection> unregisterableConnections = new ArrayList<>();
 
             NonBlockingConnection unregisteredConnection;



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org