|
Re: Setting a Thread name in a ThreadPool: msg#00059java.jsr.166-concurrency
David Harrigan wrote: > Previously, if I wanted to set a thread name, I could so something like > this: > > new Thread(new RunnableTask(), "DoSomethingWonderfulThread").start(); > > now, if I'm delgating over to an Executors, like > Executors.newCachedThreadPool(), and using that to execute my thread: > > ExecutorService s = Executors.newCachedThreadPool(); > s.execute(new RunnableTask()); > > The execute method isn't overloaded to provide a name, so, how do I go about > setting the Thread name? You implement the ThreadFactory interface to generate named threads and plug that into the ExecutorService via setThreadFactory(). public class NamedThreadFactory implements ThreadFactory { .. public Thread newThread(Runnable runnable) { return new Thread(runnable, this.createNewName()); } .. } -h
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Setting a Thread name in a ThreadPool, Mike Quilleash |
|---|---|
| Next by Date: | Re: Setting a Thread name in a ThreadPool, Kevin Condon |
| Previous by Thread: | Setting a Thread name in a ThreadPool, David Harrigan |
| Next by Thread: | Re: Setting a Thread name in a ThreadPool, Mike Quilleash |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |