设置线程池中的最小线程数
我有一个应用程序,线程池中有 4 个工作线程。它每 0.5 秒醒来一次。正如 msdn 中所写,线程池每 0.5 秒监控一次以创建空闲线程。我将最小线程数设置为 4,它解决了问题 - 不再有后台活动。我的问题是 - 我有另一个应用程序,它具有相同数量的线程 4,但这里将最小线程设置为 4 没有帮助,但当将最小线程设置为 5 时,后台监控将停止。线程池中具有相同线程数(4 个线程)的 2 个应用程序之间可能有什么区别。其中一个将最小线程设置为 4 有帮助,而另一个应用程序仅将最小线程设置为 5 有帮助?
I have an application with 4 worker threads from the thread pool. It was waking up every 0.5 second. as written in msdn the thread pool monitors every 0,5 second to create idle threads. I set the nuber of minimum threads to 4 and it solved the problem - no more background activity all the time. My question is - I have another applicatiopn which has the same number of threads threads-4, but here setting min thread to 4 doesn't help but when setting min thread to 5 then the background monitoring stops. What might be the difference between 2 application with the same number of threads from the thread pool- 4 threads.On one setting min threads to 4 helps and the other only setting min threads to 5 helps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
取决于您对线程池所做的事情。
请记住,线程池不是您想要用于长时间运行的任务的东西 - 它适用于小型、快速的作业,在这些作业中创建线程的开销将很大。
Depends on what you're doing with the thread pool.
Remember that the thread pool is not something you want to use for long-running tasks - it's intended for small, quick jobs where the overhead of creating a thread would be significant.
我建议尝试 SmartThreadPool 。
使用测试应用程序,您可以调整线程数或为其指定一些最小最大值,您可以模拟任务的持续时间......并看看会发生什么。
I would suggest to give SmartThreadPool a try.
With the test application, you can tune the number of threads or give it some min max value, you can simulate the duration on a task... and see what happens.