mirror of https://github.com/apache/activemq.git
Ensure that executor threads are created as daemon threads, fix a try/finaly block, clean up some warnings.
This commit is contained in:
parent
ebcc1b4eae
commit
5adbafef3b
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -86,8 +86,9 @@ public final class SelectorSelection {
|
|||
try {
|
||||
key.cancel();
|
||||
} catch (CancelledKeyException e) {
|
||||
} finally {
|
||||
worker.release();
|
||||
}
|
||||
worker.release();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
@ -88,9 +86,9 @@ public class SelectorWorker implements Runnable {
|
|||
Thread.currentThread().setName("Selector Worker: " + id);
|
||||
while (!isReleased()) {
|
||||
|
||||
processIoTasks();
|
||||
processIoTasks();
|
||||
|
||||
int count = selector.select(10);
|
||||
int count = selector.select(10);
|
||||
|
||||
if (count == 0) {
|
||||
continue;
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue