Thread Renaming suggestion

dralves davidralves at gmail.com
Tue Nov 16 10:56:14 EST 2010


Hi!

 I've been using Netty for a long time (great work btw) and I have a small
suggestion about thread renaming.
 I got from jira that in Netty 4.0 there is going to be a change in
ThreadNameDeterminer so that you can name threads split into the four
categories (server boss, server worker, client boss and client worker), and
I'd like to leave my 2 cents :)
 Firstly I think this new solution, i.e., extending the static method in
ThreadRenamingRunnable to accept additionally the category, is not
sufficient. In my case for instance I run multiple server pools and client
pools in the same JVM both in production and testing and while this allows
me to distinguish between the categories it does not allow me to set
different names for different pools. I mean if I run an HTTP client, an HTTP
server as well as a FTP client and Server in the same vm all the server and
client threads for both protocols would be named the same.
 Secondly IMHO, I don't get why it isn't simpler just to provide a
ThreadFactory to the Executors. I mean correct me if I am wrong, but
wouldn't it be easier just to let users do:

new NioClientSocketChannelFactory(Executors.newCachedThreadPool(new
NamedThreadFactory("NettyClientBoss")),
                    Executors.newCachedThreadPool(new
NamedThreadFactory("NettyClientWorker"));

where NamedThreadFactory is, in my case :

public class NamedThreadFactory implements ThreadFactory {

    private AtomicInteger counter = new AtomicInteger(0);
    private String        name;
    private boolean       daemon;
    private int           priority;

    public NamedThreadFactory(String name) {
        this(name, false, -1);
    }

    public NamedThreadFactory(String name, boolean daemon) {
        this(name, daemon, -1);
    }

    public NamedThreadFactory(String name, boolean daemon, int priority) {
        this.name = name;
        this.daemon = daemon;
        this.priority = priority;
    }

    @Override
    public Thread newThread(Runnable r) {
        Thread thread = new Thread(r, name + "[" + counter.getAndIncrement()
+ "]");
        thread.setDaemon(daemon);
        if (priority != -1) {
            thread.setPriority(priority);
        }
        return thread;
    }

}

... and not use the ThreadRenamingRunnable at all?.

This would allow to pass all the NamedThreadFactories one wants to any
different server and/or client Netty channel group.

As for the default thread names (pool-X-thread-Y) name replacement could
happen only when the name matched the default's name corresponding regular
expression (pool-\D+-thread-\D+ i think).

What do you think?

David


-- 
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Thread-Renaming-suggestion-tp5744313p5744313.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list