ThreadFactory usage in Java

前端 未结 10 1914
旧巷少年郎
旧巷少年郎 2020-12-02 05:08

Can someone briefly explain on HOW and WHEN to use a ThreadFactory? An example with and without using ThreadFactory might be really helpful to understand the differences.

10条回答
  •  难免孤独
    2020-12-02 05:42

    It is always a good practice to use custom thread factory. The default factories are not much of use. You should use a custom factory for the following reasons:

    1. To have custom thread names
    2. To choose between thread types
    3. To choose Thread Priority
    4. To handle uncaught exceptions

    Check this post: http://wilddiary.com/understanding-java-threadfactory-creating-custom-thread-factories/

提交回复
热议问题