确定不同Windows系统上运行的最大线程数
谁能告诉我是否有办法找出不同 Windows 系统上可以运行的最大线程数?
例如 - (假设)Windows 32 位系统最多可以运行 4000 个线程。
Can anyone tell me if there is a way to find out the maximum number of threads that can run on different windows systems?
For example - (Assumption)A windows 32-bit system can run maximum 4000 threads.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑是否有最大数量。好吧,由于我们使用的内存量是有限的,因此内存中可以容纳的线程数量或者您可以跟踪的线程数量都可以。每个系统都是不同的,我知道 Java 和 C 没有提供此功能的函数。 C# 可以告诉您特定对象/应用程序需要多少内存,以便您可以计算估计值。
您可以在您的系统上对此进行测试。编写一个生成线程的示例应用程序,并查看内存何时耗尽。使用计数器来计算它们。这将为您提供系统的大致范围。
在 Java 中,您可以将 ExecutorService 与线程池结合使用。根据您使用的执行程序服务,如果您提交更多作业,它可以继续生成线程。
C# 中也存在类似的技术。
更好的问题是生成并避免抖动的最大线程数是多少。
您是否试图接管操作系统并进行自己的进程/线程管理?你不应该这样做。
I doubt there is a maximum number. Well, since we're using a finite amount of memory, it would be as many threads as you can fit into memory or as many as you can keep track of. Each system is different and I know Java and C don't have a function to provide this. C# can tell you how much memory a specific object/app needs so you could go calculate the estimate.
You could test this on your system. Write a sample app which spawns threads and see when you run out of memory. Use a counter to count them. This will give you roughly the range for your system.
In Java, you can use an
ExecutorService
with a thread pool.. Depending on which executor service you use, it can keep spawning threads if you submit more jobs.A similar technique exists in C#.
A better question is what the maximum number of threads to spawn and avoid thrashing is.
Are you trying to take over the OS and do your own process/thread management? You should not be doing this.