[concurrency-interest] Naming threads in Executor

Tim Peierls tim at peierls.net
Sat Dec 23 14:20:03 EST 2006


You can also override TPE's beforeExecute/afterExecute methods to set the
thread name.

--tim

On 12/23/06, vladimir <dovlex at gmail.com> wrote:
>
>
> 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.
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20061223/ae7df278/attachment.html 


More information about the Concurrency-interest mailing list