You may use the overloaded method:
java.util.concurrent.Executors.newCachedThreadPool(ThreadFactory)
which allows you to pass a
java.util.concurrent.ThreadFactory
that should allow you to set the thread's names via java.util.concurrent.ThreadFactory.newThread(Runnable)
:
Constructs a new Thread
. Implementations may also initialize priority, name, daemon status, ThreadGroup
, etc.
Have a look at java.util.concurrent.Executors.DefaultThreadFactory
for a default implementation.
Addendum
Since I see that this thread is still visited, Guava (if you have it available) provides a ThreadFactoryBuilder that leverages the need of having an inner anonymous class and even allows for customizing parametrized names for your threads.