Java中的线程池有什么用? [英] What is the use of a Thread pool in Java?

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

问题描述

线程池有什么用?有一个很好的现实世界的例子吗?

What is the use of a Thread pool? Is there a good real world example?

推荐答案

线程池是最初创建的一组线程,它们等待作业并执行它们。我们的想法是让线程始终存在,这样我们就不必每次都花费很长的时间来创建它们。当我们知道要处理的工作流时,它们是合适的,即使可能有一段时间没有工作。

A thread pool is a group of threads initially created that waits for jobs and executes them. The idea is to have the threads always existing, so that we won't have to pay overhead time for creating them every time. They are appropriate when we know there's a stream of jobs to process, even though there could be some time when there are no jobs.

这是一个很好的图表来自维基百科

Here's a nice diagram from Wikipedia:

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

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