🚀 优质资源分享 🚀
学习路线指引(点击解锁) | 知识定位 | 人群定位 |
---|---|---|
🧡 Python实战微信订餐小程序 🧡 | 进阶级 | 本课程是python flask+微信小程序的完美结合,从项目搭建到腾讯云部署上线,打造一个全栈订餐系统。 |
💛Python量化交易实战💛 | 入门级 | 手把手带你打造一个易扩展、更安全、效率更高的量化交易系统 |
线程池概述
线程池,是指管理一组同构工作线程的资源池。
线程池在工作队列(Work Queue)中保存了所有等待执行的任务。工作者线程(Work Thread)会从工作队列中获取一个任务并执行,然后返回线程池并等待下一个任务。
线程池比执行任务再创建线程会有以下优势:
- 节省资源。通过重用线程来省去在线程创建和销毁过程中产生的开销。
- 提高响应性。当执行请求到达时,工作线程通常已经存在,因此不需要等待线程创建,从而提高了响应性。
- 防止资源耗尽。通过调整线程池的大小,防止过多线程相互竞争资源。
ThreadPoolExecutor
是Java中线程池的实现类。下图是继承关系:
#mermaid-1659200876080 {font-family:“trebuchet ms”,verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-1659200876080 .error-icon{fill:#552222;}#mermaid-1659200876080 .error-text{fill:#552222;stroke:#552222;}#mermaid-1659200876080 .edge-thickness-normal{stroke-width:2px;}#mermaid-1659200876080 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-1659200876080 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-1659200876080 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-1659200876080 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-1659200876080 .marker{fill:#333333;stroke:#333333;}#mermaid-1659200876080 .marker.cross{stroke:#333333;}#mermaid-1659200876080 svg{font-family:“trebuchet ms”,verdana,arial,sans-serif;font-size:16px;}#mermaid-1659200876080 g.classGroup text{fill:#9370DB;fill:#131300;stroke:none;font-family:“trebuchet ms”,verdana,arial,sans-serif;font-size:10px;}#mermaid-1659200876080 g.classGroup text .title{font-weight:bolder;}#mermaid-1659200876080 .nodeLabel,#mermaid-1659200876080 .edgeLabel{color:#131300;}#mermaid-1659200876080 .edgeLabel .label rect{fill:#ECECFF;}#mermaid-1659200876080 .label text{fill:#131300;}#mermaid-1659200876080 .edgeLabel .label span{background:#ECECFF;}#mermaid-1659200876080 .classTitle{font-weight:bolder;}#mermaid-1659200876080 .node rect,#mermaid-1659200876080 .node circle,#mermaid-1659200876080 .node ellipse,#mermaid-1659200876080 .node polygon,#mermaid-1659200876080 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-1659200876080 .divider{stroke:#9370DB;stroke:1;}#mermaid-1659200876080 g.clickable{cursor:pointer;}#mermaid-1659200876080 g.classGroup rect{fill:#ECECFF;stroke:#9370DB;}#mermaid-1659200876080 g.classGroup line{stroke:#9370DB;stroke-width:1;}#mermaid-1659200876080 .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5;}#mermaid-1659200876080 .classLabel .label{fill:#9370DB;font-size:10px;}#mermaid-1659200876080 .relation{stroke:#333333;stroke-width:1;fill:none;}#mermaid-1659200876080 .dashed-line{stroke-dasharray:3;}#mermaid-1659200876080 #compositionStart,#mermaid-1659200876080 .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-1659200876080 #compositionEnd,#mermaid-1659200876080 .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-1659200876080 #dependencyStart,#mermaid-1659200876080 .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-1659200876080 #dependencyStart,#mermaid-1659200876080 .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-1659200876080 #extensionStart,#mermaid-1659200876080 .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-1659200876080 #extensionEnd,#mermaid-1659200876080 .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-1659200876080 #aggregationStart,#mermaid-1659200876080 .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-1659200876080 #aggregationEnd,#mermaid-1659200876080 .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-1659200876080 .edgeTerminals{font-size:11px;}#mermaid-1659200876080 :root{–mermaid-font-family:“trebuchet ms”,verdana,arial,sans-serif;}Abstra