search
HomeJavaJavagetting StartedHow thread pool is implemented

How thread pool is implemented

Feb 06, 2020 pm 06:26 PM
Thread Pool

How thread pool is implemented

The thread pool has the following implementation methods:

Executors currently provides 5 different thread pool creation configurations:

1 , newCachedThreadPool()

It is a thread pool used to handle a large number of short-term work tasks. It has several distinctive features: it will try to cache threads and reuse them. When no cached threads are available, it will Create a new worker thread; if the thread is idle for more than 60 seconds, it will be terminated and the cache will be removed; when idle for a long time, this thread pool will not consume any resources. It uses SynchronousQueue internally as a work queue.

Video tutorial recommendation: java video tutorial

2. newFixedThreadPool (int nThreads)

Reuse the specified number (nThreads) Threads use an unbounded work queue behind them. At most nThreads worker threads are active at any time. This means that if the number of tasks exceeds the number of active threads, it will wait for idle threads to appear in the work queue; if the worker thread exits, a new worker thread will be created to make up for the specified number nThreads.

3. newSingleThreadExecutor()

Its characteristic is that the number of working threads is limited to 1 and it operates an unbounded work queue, so it ensures that all tasks are Being executed sequentially, at most one task will be active, and users are not allowed to change the thread pool instance, so changing the number of threads can be avoided.

4, newSingleThreadScheduledExecutor() and newScheduledThreadPool(int corePoolSize)

creates a ScheduledExecutorService, which can perform scheduled or periodic work scheduling. The difference is that a single worker thread or Multiple worker threads.

5. newWorkStealingPool(int parallelism)

This is a thread pool that is often ignored. This creation method was only added in Java 8, and ForkJoinPool will be built internally. Using the Work-Stealing algorithm, tasks are processed in parallel without guaranteeing the processing order.

Related article tutorial sharing: java quick start

The above is the detailed content of How thread pool is implemented. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:csdn. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function