About the thread pool in DOTNET

Source: Internet
Author: User
Tags dotnet
Thread Pool in Application ProgramResource allocation and processing have been optimized. If you only need to simply open several more threads to process data at the same time, and the execution time of each thread is very short, using a thread pool is a good choice.

However, if the execution time of each sub-thread is long and the total amount of data to be processed is huge, the main thread is continuously starting new threads, I personally feel that the thread pool is not a good choice.

Me
I have had such an experience. If I feel that the thread pool is used in this case, on the one hand, the speed seems to be limited,
Although the maximum number of threads in the thread pool can be changed, it is always not allowed to increase freely (of course, within the acceptable range of hardware) and cannot reach the desired speed; on the other hand, I always doubt whether it is a waiting thread.
When there are too many threads, the thread pool will automatically cut down some threads, resulting in data loss (of course, just suspect ).

Therefore, I used to control the number of threads and set a parameter as the upper limit of the total number of threads. When the total number of threads in the current process of the program exceeds the set value, wait for a while before starting the new thread. In this case, the speed is up, and no data loss is found.

The above is my personal opinion. It is for your reference only. Do you have any new ideas to share with us! I will continue to pay attention to this content in practice ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.