假设我有 1000 封流行电子邮件,我必须从中提取电子邮件。
我想创建一个利用多个线程的服务,这样我就可以同时从多个 pop3 服务器提取电子邮件(与序列化进程相反)。
我该如何去做呢?
最佳答案
API 文档中 ThreadPoolExecutor 的描述:
public class ThreadPoolExecutor extends AbstractExecutorService
An ExecutorService that executes each submitted task using one of possibly several pooled threads, normally configured using Executors factory methods.
Thread pools address two different problems: they usually provide improved performance when executing large numbers of asynchronous tasks, due to reduced per-task invocation overhead, and they provide a means of bounding and managing the resources, including threads, consumed when executing a collection of tasks. Each ThreadPoolExecutor also maintains some basic statistics, such as the number of completed tasks.
这里很简单tutorial理解相同。
一些更多的链接来理解同样的内容:
关于java - 创建具有一组线程来处理请求的服务器的指南,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3629071/