In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you how Java customizes the name of the thread pool. The content is simple and easy to understand. The organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn the article "How Java customizes the name of the thread pool".
Our software tends to use a large number of thread pools-mainly implemented via java.util.concurrent.ExecutorService (via Executors.new... created). We create these thread pools for various asynchronous use cases, and they are everywhere. All of these executors have a thread factory. It is hidden in the default factory method, but you can provide thread factories. If not, the default thread factory is used when threads are needed.
When spring is used, it can be used. In this case, the thread factory for each executor service is provided by spring, which uses the name of the executor bean (specified with id="executorName"). But for those not created by spring, using default names is unhelpful and does not allow you to distinguish threads by name.
And you need to differentiate threads by name--if a performance problem arises, you have multiple investigation options: thread dump and use the top command. In both cases, it is useful to know the functions of thread services, because stack traces in dumps may not always show up.
My favorite quick survey tool is top, or more accurately, top-H-p. This shows the usual top table, but the-H flag means that the threads of the selected process should be printed. By name, you basically get the thread that consumes the most CPU and is currently active. Custom names are useful in these situations.
But how do I set the name? By specifying a named thread factory at the time each executable is created.
The method I use is based on the second answer:
public class AsyncUtils { public static ThreadFactory createNamedThreadFactory(String name) { return new ThreadFactoryBuilder().setNameFormat(name + "-%d").build(); }}
Centralizing all executors through spring may be a better idea, but not everyone uses spring, and sometimes even a small portion of the functionality beyond spring beans requires an executor. So it's a good way.
The above is "Java how to customize the name of the thread pool" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.