activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject activemq git commit: https://issues.apache.org/jira/browse/AMQ-6108
Date Thu, 14 Jan 2016 21:48:06 GMT
Repository: activemq
Updated Branches:
  refs/heads/activemq-5.13.x 741ee01e1 -> 1d9fdbcbe


https://issues.apache.org/jira/browse/AMQ-6108

Ensure that executor threads are created as daemon threads, fix a
try/finaly block, clean up some warnings.
(cherry picked from commit 5adbafef3b9ec05de7186caa9112f3639c7a6253)


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/1d9fdbcb
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/1d9fdbcb
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/1d9fdbcb

Branch: refs/heads/activemq-5.13.x
Commit: 1d9fdbcbeaacf2d5673bb5435b1caae0b1cfc7a7
Parents: 741ee01
Author: Timothy Bish <tabish121@gmail.com>
Authored: Thu Jan 14 16:47:23 2016 -0500
Committer: Timothy Bish <tabish121@gmail.com>
Committed: Thu Jan 14 16:47:59 2016 -0500

----------------------------------------------------------------------
 .../activemq/transport/nio/SelectorManager.java |  4 +-
 .../transport/nio/SelectorSelection.java        |  3 +-
 .../activemq/transport/nio/SelectorWorker.java  | 52 +++++++++-----------
 3 files changed, 28 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/1d9fdbcb/activemq-client/src/main/java/org/apache/activemq/transport/nio/SelectorManager.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/transport/nio/SelectorManager.java
b/activemq-client/src/main/java/org/apache/activemq/transport/nio/SelectorManager.java
index 8469bac..1adb92f 100644
--- a/activemq-client/src/main/java/org/apache/activemq/transport/nio/SelectorManager.java
+++ b/activemq-client/src/main/java/org/apache/activemq/transport/nio/SelectorManager.java
@@ -50,8 +50,8 @@ public final class SelectorManager {
 
                 @Override
                 public Thread newThread(Runnable runnable) {
-                    this.i++;
-                    final Thread t = new Thread(runnable, "ActiveMQ NIO Worker " + this.i);
+                    Thread t = new Thread(runnable, "ActiveMQ NIO Worker " + (i++));
+                    t.setDaemon(false);
                     return t;
                 }
             });

http://git-wip-us.apache.org/repos/asf/activemq/blob/1d9fdbcb/activemq-client/src/main/java/org/apache/activemq/transport/nio/SelectorSelection.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/transport/nio/SelectorSelection.java
b/activemq-client/src/main/java/org/apache/activemq/transport/nio/SelectorSelection.java
index 01480a0..a0dd210 100644
--- a/activemq-client/src/main/java/org/apache/activemq/transport/nio/SelectorSelection.java
+++ b/activemq-client/src/main/java/org/apache/activemq/transport/nio/SelectorSelection.java
@@ -86,8 +86,9 @@ public final class SelectorSelection {
                     try {
                         key.cancel();
                     } catch (CancelledKeyException e) {
+                    } finally {
+                        worker.release();
                     }
-                    worker.release();
                 }
             });
         }

http://git-wip-us.apache.org/repos/asf/activemq/blob/1d9fdbcb/activemq-client/src/main/java/org/apache/activemq/transport/nio/SelectorWorker.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/transport/nio/SelectorWorker.java
b/activemq-client/src/main/java/org/apache/activemq/transport/nio/SelectorWorker.java
index e55e378..1a32346 100644
--- a/activemq-client/src/main/java/org/apache/activemq/transport/nio/SelectorWorker.java
+++ b/activemq-client/src/main/java/org/apache/activemq/transport/nio/SelectorWorker.java
@@ -35,7 +35,7 @@ public class SelectorWorker implements Runnable {
 
     final AtomicInteger retainCounter = new AtomicInteger(1);
     private final ConcurrentLinkedQueue<Runnable> ioTasks = new ConcurrentLinkedQueue<Runnable>();
-       
+
     public SelectorWorker(SelectorManager manager) throws IOException {
         this.manager = manager;
         selector = Selector.open();
@@ -57,20 +57,19 @@ public class SelectorWorker implements Runnable {
             manager.onWorkerNotFullEvent(this);
         }
     }
-    
+
     boolean isReleased() {
-        return retainCounter.get()==0;
+        return retainCounter.get() == 0;
     }
 
-
     public void addIoTask(Runnable work) {
         ioTasks.add(work);
         selector.wakeup();
     }
-    
+
     private void processIoTasks() {
-        Runnable task; 
-        while( (task= ioTasks.poll()) !=null ) {
+        Runnable task;
+        while ((task = ioTasks.poll()) != null) {
             try {
                 task.run();
             } catch (Throwable e) {
@@ -79,34 +78,33 @@ public class SelectorWorker implements Runnable {
         }
     }
 
-    
-
+    @Override
     public void run() {
 
         String origName = Thread.currentThread().getName();
         try {
             Thread.currentThread().setName("Selector Worker: " + id);
             while (!isReleased()) {
-            	
-            	processIoTasks();
-            	
-            	int count = selector.select(10);
-            	
+
+                processIoTasks();
+
+                int count = selector.select(10);
+
                 if (count == 0) {
                     continue;
                 }
 
                 // Get a java.util.Set containing the SelectionKey objects
                 // for all channels that are ready for I/O.
-                Set keys = selector.selectedKeys();
+                Set<SelectionKey> keys = selector.selectedKeys();
 
-                for (Iterator i = keys.iterator(); i.hasNext();) {
-                    final SelectionKey key = (SelectionKey)i.next();
+                for (Iterator<SelectionKey> i = keys.iterator(); i.hasNext();) {
+                    final SelectionKey key = i.next();
                     i.remove();
 
-                    final SelectorSelection s = (SelectorSelection)key.attachment();
+                    final SelectorSelection s = (SelectorSelection) key.attachment();
                     try {
-                        if( key.isValid() ) {
+                        if (key.isValid()) {
                             key.interestOps(0);
                         }
 
@@ -114,6 +112,7 @@ public class SelectorWorker implements Runnable {
                         // while we process the
                         // currently selected keys
                         manager.getChannelExecutor().execute(new Runnable() {
+                            @Override
                             public void run() {
                                 try {
                                     s.onSelect();
@@ -127,17 +126,15 @@ public class SelectorWorker implements Runnable {
                     } catch (Throwable e) {
                         s.onError(e);
                     }
-
                 }
-
             }
-        } catch (Throwable e) {         	
+        } catch (Throwable e) {
             e.printStackTrace();
             // Notify all the selections that the error occurred.
-            Set keys = selector.keys();
-            for (Iterator i = keys.iterator(); i.hasNext();) {
-                SelectionKey key = (SelectionKey)i.next();
-                SelectorSelection s = (SelectorSelection)key.attachment();
+            Set<SelectionKey> keys = selector.keys();
+            for (Iterator<SelectionKey> i = keys.iterator(); i.hasNext();) {
+                SelectionKey key = i.next();
+                SelectorSelection s = (SelectorSelection) key.attachment();
                 s.onError(e);
             }
         } finally {
@@ -145,10 +142,9 @@ public class SelectorWorker implements Runnable {
                 manager.onWorkerEmptyEvent(this);
                 selector.close();
             } catch (IOException ignore) {
-            	ignore.printStackTrace();
+                ignore.printStackTrace();
             }
             Thread.currentThread().setName(origName);
         }
     }
-
 }


Mime
View raw message