I'm using an ExecutorService to execute some Callables, but the name of the threads are like fixed-pool-1-thread-1.
How I change the name of the threads? If it's not possible, there another way to execute Callables that I can set the name of threadS?
You'll have to use an ExecutorService
implementation that allows you to set the ThreadFactory
1 used to create threads, for example, ThreadPoolExecutor
. Pass an instance that creates threads with the proper names.
There's also a handy class in commons-lang that allows to specify thread names with a pattern: BasicThreadFactory
. This keeps you from having to create a ThreadFactory
subclass just to provide the naming behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With