Thread Renaming suggestion

"이희승 (Trustin Lee)" trustin at gmail.com
Mon Jan 10 00:46:14 EST 2011


David,

I love the idea, and let me accept your suggestion for 4.0. :-)

Cheers,
Trustin

On 11/17/2010 12:56 AM, dralves wrote:
> 
> 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
> 
> 

-- 
Trustin Lee, http://gleamynode.net/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 294 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20110110/08e67882/attachment.bin 


More information about the netty-users mailing list