问题:
Let's say I have an application that utilizes the Executor
framework as such假设我有一个使用Executor
框架的应用程序
Executors.newSingleThreadExecutor().submit(new Runnable(){
@Override
public void run(){
// do stuff
}
}
When I run this application in the debugger, a thread is created with the following (default) name: Thread[pool-1-thread-1]
.当我在调试器中运行此应用程序时,会创建一个具有以下(默认)名称的Thread[pool-1-thread-1]
: Thread[pool-1-thread-1]
。 As you can see, this isn't terribly useful and as far as I can tell, the Executor
framework does not provide an easy way to name the created threads or thread-pools.如您所见,这并不是很有用,据我所知, Executor
框架没有提供一种简单的方法来命名创建的线程或线程池。
So, how does one go about providing names for the threads/thread-pools?那么,如何为线程/线程池提供名称呢? For instance, Thread[FooPool-FooThread]
.例如, Thread[FooPool-FooThread]
。
解决方案:
参考一: https://en.stackoom.com/question/PeSo参考二: https://stackoom.com/question/PeSo