problem description
where should the Java thread pool be created? Or whether a thread pool is used for one business, multiple businesses, or the whole project
where should the Java thread pool be created? Or whether a thread pool is used for one business, multiple businesses, or the whole project
Thread pools generally follow the project and are created when the project starts. For example, when servlet initializes, initialize a global thread pool
the question you are asking is too abstract to know exactly where your confusion lies.
A thread pool can be used for one business or multiple services, which needs to be analyzed according to specific scenarios. It has nothing to do with the project, the project is the concept of software construction process, how many thread pools you need for a software system depends entirely on your business scenario.
for example, Web servers usually have a thread pool for processing http requests. This is a single business scenario. A system has a fixed thread pool in which several tasks are regularly run to handle different businesses. This is a multi-business scenario.
forget which book I read that thread pools should be for the entire project, not for a single business.
Why do you say that? What is the thread pool facing? It's CPU. In any case, CPU can handle so many things.
-the following is what I think of myself-
but it is not absolute either. For example, for two businesses, one needs 1ms for business processing and the other needs 1h. If the front part of the thread pool is all filled with 1h tasks and 1ms has no chance to execute it, it will not be embarrassing. Although there are many mechanisms to avoid this situation, that is what he said again.
so it's a bit of a problem to definitely use the same thread pool.
the above is just a wild guess. Don't blame me if you are wrong, .
Previous: Cannot use the replication function of spring?
Next: Use splice to remove the specified items in the array, the result is incorrect