螺纹VS线程池 - .NET 2.0 [英] Thread vs ThreadPool - .Net 2.0

查看:244
本文介绍了螺纹VS线程池 - .NET 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能够理解VS线程池线程之间的差异。考虑我已经使用线程来处理50,000条记录。

I'm not able to understand the difference between Thread vs ThreadPool. Consider i've to manipulate 50,000 records using threads.

在线程的情况下我需要或者predefine没有螺纹或无每线程记录。其中的任一必须是恒定的。

In case of threads i need to either predefine no of threads or no of records per threads. Either of them has to be constant.

在线程池的情况下,我们不需要设置任何他们的理论。但实际上,我们需要分配的每个线程记录的数量,因为没有线程可能增长非常大,如果没有输入记录是巨大的。

In case of threadpool we dont need to set any of them theoretically. But practically we need to assign the number of records per thread, because the no of threads may grow extremely large if the input no of records is huge.

对此有何见解?

推荐答案

有一个在创建和销毁线程巨大的成本。线程池带走了这个问题,保持开放的主题为您服务。当在池中的线​​程与它的工作完成后,该线程返回到池,而不是被破坏。然后,当你必须做更多的工作,已经开​​线是从池中。这是更有效的。

There is a huge cost in creating and destroying threads. A thread pool takes away this problem by maintaining open threads for you. When a thread in a pool is done with its work, the thread is returned to the pool instead of being destroyed. Then when you have to do more work, the already open thread is taken from the pool. This is much more efficient.

这篇关于螺纹VS线程池 - .NET 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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