Table of Contents For thread pool parameters For task submission strategy Respond quickly to user requests The default strategy of java ThreadPoolExecutor is as follows The tomcat ThreadPoolExecutor strategy is as follows Process batch tasks quickly Thread pool monitoring Dynamic adjustment of thread pool parameters https://mp.weixin.qq.com/s/baYuX8aCwQ9PP6k7TDl2Ww Java thread pool implementation principle and its practice in […]
Tag: executor
KeepAliveTime analysis in ThreadPoolExecutor
keepAliveTime is the time that idle threads in the thread pool wait for tasks. If this time is exceeded, the thread pool will kick the current thread out of the thread pool. Divided into two scenarios: allowCoreThreadTimeout is set to true. After all idle threads in the thread pool time out, getTask() returns null, and […]
28.Thread pool ThreadPoolExecutor actual combat and analysis of its principles
Five states of thread pool The high three bits of the variable ctl of the AtomicInteger type are used to represent the status of the thread pool, and the other digits represent the number of worker threads in the thread pool. RUNNING Accept new tasks and process queued tasks The thread pool is running normally […]
java thread pool ThreadPoolExecutor and ThreadPoolTaskExecutor
Foreword 1. What are the benefits of using a thread pool Reduce resource consumption. Reduce the cost of thread creation and destruction by reusing created threads. Improve responsiveness. When a task arrives, the task can be executed immediately without waiting for the thread to be created. Improve thread manageability. Threads are scarce resources. If they […]
Concurrent programming – ScheduledThreadPoolExecutor
Article directory Introduction to ScheduledThreadPoolExecutor ScheduledFutureTask Four ways to perform tasks execute method schedule method Analysis of scheduleAtFixedRate and scheduleWithFixedDelay Introduction to ScheduledThreadPoolExecutor ScheduledThreadPoolExecutor is a subclass of ThreadPoolExecutor, which implements the function of delayed execution of tasks and periodic execution of tasks based on the thread pool. The first thing Java provided was the […]
Use of Executors
Use of Executors 1. Thread pool working sequence corePoolSize -> task queue -> maximumPoolSize -> deny policy 2. The factory method of the built-in thread pool 1. newFixedThreadPool JDK documentation description: Create a fixed ready-made pool that reuses a fixed number of threads. If all threads are active and there are new tasks, they will […]
Thread pool ThreadPoolExecutor implements parallel processing
1. Define an interface Animal package com.zh.vo; public interface Animal { void work(); } 2. Define an implementation class Bird package com.zh.vo; public class Bird implements Animal { @Override public void work() { int sum = 0; for (int i = 0; i < 100000; i + + ) { sum + = i; } […]
xxl-job source code interpretation: executor Excutor call link
This article is based on version 2.3.1 of xxl-job The executor, that is, the service where the task logic code is located, that is, your business project, is requested by the trigger of the dispatch center through the network to call the execution of the task. 1. Executor client loading When obtaining the executor client, […]
spring data jpa defines interface and inherits JpaSpecificationExecutor<T> to implement dynamic query
This interface can implement jpa dynamic query based on parameters, similar to dynamic sql query based on whether parameters are passed in mybatis. layer package com.choorn.serverboot.dao; import com.choorn.serverboot.entity.Income; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.repository.PagingAndSortingRepository; public interface IncomeDao extends PagingAndSortingRepository<Income,Long>, JpaSpecificationExecutor<Income> { } service layer implementation package com.choorn.serverboot.service.impl; import com.choorn.serverboot.dao.IncomeDao; import com.choorn.serverboot.dto.IncomeSearchDTO; import com.choorn.serverboot.entity.Income; import com.choorn.serverboot.service.IncomeService; import org.springframework.beans.factory.annotation.Autowired; […]
Use ThreadPoolExecutor to create a thread pool and complete parallel operations
Many extremely inefficient operations in many places in daily work can often be changed from serial to parallel, and the execution efficiency is often improved several times. Without further ado, let’s start with the code. 1. Guava coordinates used <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>18.0</version> </dependency> View Code 2. Create an enumeration to ensure that the thread […]