Hello,
I'm using Mina 2.0.0-RC1
I'm trying to set meaningful thread names for the IoAcceptor and
IoProcessor thread pools I use in my code.
To this effect, I use the related constructors that allow me to set my
own thread pool with a custom thread factory, for example:
int size = Runtime.getRuntime().availableProcessors() + 1;
IoProcessor processor = new NioProcessor(
createExecutor("Class Server Processor", size));
NioAcceptor acceptor = new NioSocketAcceptor(
createExecutor("Class Server Acceptor", size), processor);
private ExecutorService createExecutor(String baseName, int size)
{
ThreadFactory fact = new JPPFThreadFactory(baseName);
return Executors.newFixedThreadPool(size, fact);
}
The probem is that when I debug or take a thread dump, the thread names
come out as "NioProcessor-1" and "NioAcceptor-1" (or something similar)
nonetheless.
Looking into the code of 2.0.0-RC1, I noticed that whatever is submitted
to the executors is wrapped into a NamePreservingRunnable, whose only
role seems to be renaming the thread at the start of the Runnable's
run() method, and putitng back the old name at the end of run().
I've seen two instances of that happening in the code of Mina-core:
1) in org.apache.mina.core.service.AbstractIoService
protected final void executeWorker(Runnable worker, String suffix) {
String actualThreadName = threadName;
if (suffix != null) {
actualThreadName = actualThreadName + '-' + suffix;
}
executor.execute(new NamePreservingRunnable(worker, actualThreadName));
//executor.execute(worker);
}
2) in org.apache.mina.core.polling.AbstractPolllingIoProcessor
private void startupProcessor() {
synchronized (lock) {
if (processor == null) {
processor = new Processor();
executor.execute(new NamePreservingRunnable(processor,
threadName));
//executor.execute(processor);
}
}
}
I made the following modications:
in 1) I replaced
executor.execute(new NamePreservingRunnable(worker, actualThreadName));
with
executor.execute(worker);
and in 2) I replaced
executor.execute(new NamePreservingRunnable(processor,
threadName));
with
executor.execute(processor);
After this, I was able to see the tread names I desired, without any
observed adverse effect.
So I have the following questions:
- is there any point at all in wrapping the executor tasks into a
NamePreservingRunnable instance? It seems to consume additional cpu
cycles for little or no benefit.
- should this be considered a bug, and if so, would you like me to
register it in Jira?
Thanks for your time.
Sincerely,
-Laurent