Home > Back-end >  Java thread pool core number of threads, the maximum number of threads, the work queue bounded numbe
Java thread pool core number of threads, the maximum number of threads, the work queue bounded numbe

Time:04-30

1. First of all, I is baidu, basic same, n n + 1, 2, and according to the time calculate, basically is the fuzzy

Do 2. Consult a Java background by 15/30/45/60/75% years of work experience, the answer, say some is after baidu told me, oneself also said confused

3. Look at some of the tripartite framework using the thread pool, how to set up, there is not a specific formula or algorithm

, every brother please give directions, are there any authoritative algorithm, set these parameters according to what can figure out the optimal numerical

CodePudding user response:

There is no fixed calculation

CodePudding user response:

General core CPU intensive tasks, the number of threads is set to n, the calculation of IO intensive tasks I forget, seemed very complex, and related to your task of IO time-consuming than, what work queue to see your own business

CodePudding user response:

I don't remember I saw it read book, it is possible that the art of concurrent Java programming,,,

CodePudding user response:

What the optimal, is that a few thread pool type, there are N the scenario used. According to the need to choose. Separate the IO intensive and CPU concentration areas after is some custom configuration

CodePudding user response:

reference 4 floor a975719898 response:
what the optimal, is that a few thread pool type, there are N the scenario used. According to the need to choose. Separate the IO intensive and CPU concentration areas after is some custom configuration
create a thread pool commonly when not with fixed that several types but a custom thread pool, fixed type have disadvantages

CodePudding user response:

reference 3 floor seven sea my wife's reply:
I don't remember I saw it read book, it is possible that the art of concurrent Java programming,,
into the book and see how I say

CodePudding user response:

1. Specially baidu once, the fundamental problem is not all say clear? If you feel fuzzy, please give out the fuzzy point
2. If you want to say, in fact, basic it is by feeling, especially the cpu-intensive, because it is almost impossible to a server running a project only
3. What framework? The code listed

CodePudding user response:

The workings of a thread pool is about this
1. When a task is submitted to the thread pool, first check to see if the core of the thread pool threads are on a mission, or choose a thread to perform a task, is the second step is executed,
2. Check to see if the core thread pool is full, it create a thread to perform a task, or implement the third step,
3. Check to see if the task queue is full, the dissatisfaction will task stored in task queue, otherwise perform step 4,
4. Check to see if the thread pool is full, it create a thread to perform a task, otherwise we are unable to perform tasks in accordance with the strategy,

I think so, you can reference, may also have some understanding does not reach the designated position, also please correct me

1. Considering the current use of server performance and business to sleep, and the premise of guarantee business conditions to consider performance
Such as: your server is a few nuclear support several threads, whether to support hyper-threading, which decide the effect of multithreading, such as your server is 4 core support 8 threads, thread pool configuration to 100 threads, you most can only 8 threads at the same time to work properly, or multiple work together each other plunder instead more CPU resources speed is slow,
2. Think about business and processing performance, if you are dozens each task per second, 10 thread of the thread you use, 1000 queue, also can't use, instead of taking up resources, analysis of the data about quantity and processing speed calculate how many normal can guarantee business
3. Monitor after a period of time to adjust the tuning




CodePudding user response:

reference PNZ. The eighth floor BeijingL response:
the workings of a thread pool is about this
1. When a task is submitted to the thread pool, first check to see if the core of the thread pool threads are on a mission, or choose a thread to perform a task, is the second step is executed,
2. Check to see if the core thread pool is full, it create a thread to perform a task, or implement the third step,
3. Check to see if the task queue is full, the dissatisfaction will task stored in task queue, otherwise perform step 4,
4. Check to see if the thread pool is full, it create a thread to perform a task, otherwise we are unable to perform tasks in accordance with the strategy,

I think so, you can reference, may also have some understanding does not reach the designated position, also please correct me

1. Considering the current use of server performance and business to sleep, and the premise of guarantee business conditions to consider performance
Such as: your server is a few nuclear support several threads, whether to support hyper-threading, which decide the effect of multithreading, such as your server is 4 core support 8 threads, thread pool configuration to 100 threads, you most can only 8 threads at the same time to work properly, or multiple work together each other plunder instead more CPU resources speed is slow,
2. Think about business and processing performance, if you are dozens each task per second, 10 thread of the thread you use, 1000 queue, also can't use, instead of taking up resources, analysis of the data about quantity and processing speed calculate how many normal can guarantee business
3. Monitor after a period of time to adjust the tuning

principle who all understand, you this analysis I think reasonable, also should be considered in the actual place

CodePudding user response:

Look at your thread pool is mainly used to do what kind of task, if it is CPU intensive tasks, such as a large number of calculations, can set the number of threads and CPU core is consistent, thread switches will also consume resources, if the open too much, the cost of switching between threads is increased,

If a task is mainly to read and write, basic has nothing to do with computing, can put the number of threads to open more,

Actually, there is no fixed the problem answer, according to the actual task type, comprehensive factors such as machine hardware configuration,

In addition to consider task processing tasks and tasks submission speed, if the submitted quickly, slowly, so will the number of tasks in a queue backlog, maximum will be refused, if the queue size is unrestricted, finally will die because of insufficient physical memory,

  • Related