java中线程池的类型 [英] Types of Thread Pools in java

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

问题描述

java中的线程池有哪些类型。我需要实现一个强大的多线程应用程序,它使用繁重的计算,我应该使用哪个线程池?

What are the types of thread pools in java. I need to implement a robust multi-threaded application which uses heavy computation, which thread pool should I use?

推荐答案

有各种各样的java中的线程池:

There are various thread pools in java:


  • 单线程执行程序:只有一个线程的线程池。因此,所有提交的任务将按顺序执行。方法: Executors.newSingleThreadExecutor()

缓存线程池:创建尽可能多线程的线程池它需要以并行方式执行任务。旧的可用线程将重新用于新任务。如果在60秒内未使用某个线程,它将被终止并从池中删除。方法: Executors.newCachedThreadPool()

Cached Thread Pool : A thread pool that creates as many threads it needs to execute the task in parrallel. The old available threads will be reused for the new tasks. If a thread is not used during 60 seconds, it will be terminated and removed from the pool. Method : Executors.newCachedThreadPool()

固定线程池:具有固定数量的线程池线程。如果某个线程不可用于该任务,则该任务将进入队列,等待其他任务结束。方法: Executors.newFixedThreadPool()

Fixed Thread Pool : A thread pool with a fixed number of threads. If a thread is not available for the task, the task is put in queue waiting for an other task to ends. Method : Executors.newFixedThreadPool()

预定线程池:用于安排未来任务的线程池。方法: Executors.newScheduledThreadPool()

Scheduled Thread Pool : A thread pool made to schedule future task. Method : Executors.newScheduledThreadPool()

单线程预定池:只有一个线程的线程池安排未来的任务。方法: Executors.newSingleThreadScheduledExecutor()

Single Thread Scheduled Pool : A thread pool with only one thread to schedule future task. Method : Executors.newSingleThreadScheduledExecutor()

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

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