Ensure that executor threads are created as daemon threads, fix a
try/finaly block, clean up some warnings.
This commit is contained in:
Timothy Bish 2016-01-14 16:47:23 -05:00
parent ebcc1b4eae
commit 5adbafef3b
3 changed files with 29 additions and 32 deletions

View File

@ -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;
}
});

View File

@ -86,9 +86,10 @@ public final class SelectorSelection {
try {
key.cancel();
} catch (CancelledKeyException e) {
}
} finally {
worker.release();
}
}
});
}
}

View File

@ -59,10 +59,9 @@ public class SelectorWorker implements Runnable {
}
boolean isReleased() {
return retainCounter.get()==0;
return retainCounter.get() == 0;
}
public void addIoTask(Runnable work) {
ioTasks.add(work);
selector.wakeup();
@ -70,7 +69,7 @@ public class SelectorWorker implements Runnable {
private void processIoTasks() {
Runnable task;
while( (task= ioTasks.poll()) !=null ) {
while ((task = ioTasks.poll()) != null) {
try {
task.run();
} catch (Throwable e) {
@ -79,8 +78,7 @@ public class SelectorWorker implements Runnable {
}
}
@Override
public void run() {
String origName = Thread.currentThread().getName();
@ -98,15 +96,15 @@ public class SelectorWorker implements Runnable {
// 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) {
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 {
@ -150,5 +147,4 @@ public class SelectorWorker implements Runnable {
Thread.currentThread().setName(origName);
}
}
}