许多程序会动态创建数十个设置上百个线程.举个例子,一个web服务器可能在每一个新到来的请求时创建一个新线程,然后在请求完成后将其终止.

然而,创建一个新线程将会带来一定的耗费:它需要在内核中创建自身必要的数据结构(并且最终销毁),它需要一定时间来设置这些数据结构.

虽然内核对于创建一个新线程已经非常有效率了,但是那些需要创建成百上千线程的程序来说,这依然是性能的瓶颈所在.

线程池是被设计用来减轻这个问题.当程序开始时,它可能创建一定数量的线程并将他们放在线程池中.当其需要新线程时,他将从池子中获取一个,使用它来完成一些工作,并且最终放回到线程池中.有了线程池,创建新线程的花费将降至最低.

NSThread自身并不提供任何线程池的机制.在GCD(Grand Central Dispatch)之前,程序员必须自己处理线程池.而使用前面介绍的GCD,线程池将在幕后被处理,使得特定硬件上运行程序时,使用成百上千的线程将会非常有效率和最优化!

Thread Pools的更多相关文章

  1. Java theory and practice: Thread pools and work queues--reference

    Why thread pools? Many server applications, such as Web servers, database servers, file servers, or ...

  2. Thread pools & Executors

    Thread pools & Executors Run your concurrent code in a performant way All about thread pools # H ...

  3. 小规模的流处理框架.Part 1: thread pools

    原文链接:http://ifeve.com/part-1-thread-pools/ 很不错的一篇文章

  4. The CLR's Thread Pool

    We were unable to locate this content in zh-cn. Here is the same content in en-us. .NET The CLR's Th ...

  5. Improve Scalability With New Thread Pool APIs

    Pooled Threads Improve Scalability With New Thread Pool APIs Robert Saccone Portions of this article ...

  6. CLR thread pool

    Thread Pooling https://msdn.microsoft.com/en-us/library/windows/desktop/ms686756(v=vs.85).aspx Threa ...

  7. java thread reuse(good)

    I have always read that creating threads is expensive. I also know that you cannot rerun a thread. I ...

  8. Thread -- Request

    Servlet容器应该绝大部分(有可能全部)是Thread per Request,每个请求一个线程.此外有Thread per Connection,应该不是用于Servlet容器.请见 How a ...

  9. How does a single thread handle asynchronous code in JavaScript?

    原文:https://www.quora.com/How-does-a-single-thread-handle-asynchronous-code-in-JavaScript ----------- ...

随机推荐

  1. 超级好用的前端开发测试Chrome插件-基于REST的Web服务客户端

    基于REST的Web服务客户端是一款功能强大的谷歌浏览器插件,使用基于REST的Web服务客户端(模拟REST客户端)可以让用户使用谷歌浏览器模拟REST请求来测试REST风格. 基于REST的Web ...

  2. jquery checkbox勾选/取消勾选checked属性不生效问题

    http://www.cnblogs.com/KeenLeung/p/3799895.html

  3. [LeetCode] Bold Words in String 字符串中的加粗单词

    Given a set of keywords words and a string S, make all appearances of all keywords in S bold. Any le ...

  4. tkinter 创建登陆注册界面

    import tkinter as tk from tkinter import messagebox #设置窗口居中 def window_info(): ws = window.winfo_scr ...

  5. java利用poi来读取execl表格返回对象

    利用poi来读取execl表格,返回一个对象(可能有点不完善,但是应该能满足平常的所用),用到了反射等等; 使用的jar包有: commons-collections4-4.1.jar poi-3.1 ...

  6. 机器学习基石:08 Noise and Error

    噪声:误标.对同一数据点的标注不一致.数据点信息不准确...... 噪声是针对整个输入空间的. 存在噪声的情况下,VC bound依旧有用: 存在噪声,就是f------>p(y|x),f是p的 ...

  7. 树莓派控制HC-SR04超声波模块测距(新手向+C语言向)

    因为作业要求使用c语言代码,这里先附上一段摘自网上的代码 感谢KalaerSun的c语言代码,摘自https://blog.csdn.net/qq_25247589/article/details/6 ...

  8. [HNOI 2015]菜肴制作

    Description 知名美食家小 A被邀请至ATM 大酒店,为其品评菜肴. ATM 酒店为小 A 准备了 N 道菜肴,酒店按照为菜肴预估的质量从高到低给予 1到N的顺序编号,预估质量最高的菜肴编号 ...

  9. [NOIp 2014]飞扬的小鸟

    Description Flappy Bird 是一款风靡一时的休闲手机游戏.玩家需要不断控制点击手机屏幕的频率来调节小鸟的飞行高度,让小鸟顺利通过画面右方的管道缝隙.如果小鸟一不小心撞到了水管或者掉 ...

  10. hdu 5868 Polya计数

    Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K ...