[concurrency-interest] Naming threads in Executor

vladimir dovlex at gmail.com
Sat Dec 23 10:45:44 EST 2006


Hi,

Executor framework provide a mechanism to name threads that are used within
the framework. Once created these thread names are constant for their
lifetime. How would you attach some additional information to a thread name
as it runs various Runnables in Executor framework? They only way of doing
this seems to be setting a thread name ( Thread.currentThread.setName())
within run method of the Runnable. For example:

             executor.execute(new Runnable() {
                public void run() {
                    Thread runner = Thread.currentThread();
                    String oldName = runner.getName();
                    try
                    {
                       runner.setName(oldName+......); 
                       //do some work here                      
                    }
                    finally
                    {
                       runner.setName(oldName);
                    }                    
                }               
            });

Do you anticipate any problems with this approach? Btw, it is strange that
the name variable of Thread class does not seem to be thread safe. Any
ideas?

Regards,
Vladimir

-- 
View this message in context: http://www.nabble.com/Naming-threads-in-Executor-tf2874658.html#a8034578
Sent from the JSR166 Concurrency mailing list archive at Nabble.com.



More information about the Concurrency-interest mailing list