ExecutorService 的命名線程和線程池 - Naming threads and thread-pools of ExecutorService

問題:

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章