如何在线程池中设置最大线程? [英] How can I set the max thread in threadpool?

查看:137
本文介绍了如何在线程池中设置最大线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行项目时,线程的计数将增加,大约30分钟后,线程的计数将增加到1000+,并导致OutOfMemory异常。

我试图使用ThreadPool.SetMaxThreads来限制线程的最大数量,而我不知道哪些数量的最大线程是合适的。它是否与计算机核心有关系?

解决方案

OutOfMemory 当你在32位系统上出现异常时内存使用量超过〜2GB。



1)尝试在64位系统上运行。

2)认真重新思考你是如何做事的当线程运行30分钟而不重用时。

3)尝试使用任务而不是线程,因为它们的资源更轻。

when I run the projects, the counts of the threads will increase ,and after about 30 minutes the counts of the threads will be to 1000+, and cause the OutOfMemory Exception.
I have tried to use the ThreadPool.SetMaxThreads which will limited the max counts of the threads, while I don't know which numbers of the max threads would be suitable. Does it be relational with the cores of the computers?

解决方案

OutOfMemory exceptions occur mostly on 32bit systems when you reach more than ~2gb memory usage.

1) Try running on a 64bit system.
2) Seriously rethink how you are doing things when you have thread running for 30 minutes without reuse.
3) Try using Tasks instead of threads since they are lighter on resources.


这篇关于如何在线程池中设置最大线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆