The article explains how Spring's @Async annotation works, compares synchronous and asynchronous calls, reviews the built‑in executors such as SimpleAsyncTaskExecutor, discusses their drawbacks, and provides detailed guidance on creating custom thread pools via AsyncConfigurer, AsyncConfigurerSupport, or a TaskExecutor bean, including code examples.
This article explains how a JDK bug in ScheduledExecutorService can cause a thread pool with coreSize 0 to enter a tight loop, driving CPU usage to 100 %, and shows the fixes introduced in JDK 9 as well as a related bug in scheduleWithFixedDelay.
This article explains how RocketMQ creates and manages threads, covering single‑thread creation via Runnable and Thread inheritance, the ServiceThread abstract class, ThreadPoolExecutor configuration, custom thread factories, and the importance of descriptive thread names for debugging.
This article explains Java's CompletableFuture API introduced in JDK 8, covering how to create asynchronous tasks with supplyAsync and runAsync, use various callback methods such as thenApply, thenAccept, thenRun, whenComplete, handle, and combine multiple futures with thenCombine, allOf, anyOf, providing code examples and execution results.
This article explains what MDC (Mapped Diagnostic Context) is, outlines its API, demonstrates how to configure logging and interceptors, and provides concrete solutions—including a custom thread‑pool wrapper and HTTP client interceptors—to ensure TraceId is correctly propagated across threads and remote calls in Java backend systems.
This article explains why tasks submitted to a Java ThreadPool via submit do not print exceptions, how to retrieve them using Future.get(), and presents three practical solutions—including try‑catch, Thread.setDefaultUncaughtExceptionHandler, and overriding afterExecute—to reliably capture and process thread pool exceptions.
The DynamicTp framework extends Java's ThreadPoolExecutor with runtime‑adjustable parameters, real‑time monitoring, alerting, and integration with multiple configuration centers, offering a lightweight, zero‑intrusion solution for microservice environments to improve performance and reliability.
DynamicTp is a Java library that extends ThreadPoolExecutor to enable dynamic, configuration‑center‑driven adjustment of thread‑pool parameters, real‑time monitoring, alert notifications, and metric collection, providing a lightweight, zero‑intrusion solution for microservice architectures.
This article examines the MemoryLimitedLBQ and MemorySafeLBQ implementations, explains how they use memory‑limiting techniques to avoid Out‑Of‑Memory errors in unbounded LinkedBlockingQueue‑based thread pools, compares their designs, and shows practical code snippets for integrating them into Java projects.
The article details a sudden CPU spike in a Java backend service using Nacos, walks through diagnosing the offending thread with top and jstack, analyzes Nacos client thread creation and scheduled gray‑config tasks, explains Raft network partition handling, and presents a fix that checks config health and avoids unnecessary thread creation.
This article explains Spring's TaskExecutor and TaskScheduler abstractions, their various implementations, how they decouple threading and scheduling from the deployment environment, and provides practical code examples for configuring and using them in Java applications.
This article demonstrates how to integrate Thumbnailator for image watermarking and thumbnail generation, configure a SpringBoot thread pool, and use asynchronous @Async methods together with FastDFS storage to efficiently handle bulk image uploads in a backend service.
This article introduces asynchronous programming concepts in Java, explaining the shift from synchronous to asynchronous execution, and demonstrates practical implementations using raw threads, ThreadPoolExecutor, Future, FutureTask, CompletableFuture, and Spring's @Async annotation, along with event handling and message queue integration for high‑throughput systems.
This article demonstrates how to integrate the Thumbnailator library with SpringBoot, configure a thread pool, and implement asynchronous image processing and upload using FastDFS, providing complete code examples, configuration tips, and common pitfalls to avoid.
This article explains a Java technique for limiting asynchronous task execution to a fixed queries‑per‑second rate using a Semaphore‑based thread pool, a LinkedBlockingQueue, and a daemon thread that manages task dispatch, shutdown, and idle waiting.
This article explains why creating threads repeatedly wastes resources, introduces Java's ExecutorService thread pool, details its configuration parameters, demonstrates how to create and use fixed thread pools with Runnable and Callable tasks, shows proper shutdown, and highlights common pitfalls with Future.get.
This article examines how ScheduledThreadPoolExecutor can lose exception information and stop rescheduling periodic tasks when a task throws an exception, by walking through the source code flow, the runAndReset logic, and the resulting behavior.
This article explains how to use Java's java.util.concurrent.Semaphore together with a fixed-size thread pool to enforce a precise QPS limit for asynchronous tasks, providing API details, implementation steps, and a complete test example.
This article explains the different delay and periodic task types supported by Java's ScheduledThreadPoolExecutor, details its constructor parameters and default settings, and highlights common pitfalls such as exception loss, inaccurate scheduling, and improper core pool size configuration.
This article explains why tasks submitted to a Java thread pool via submit do not print exceptions, how to retrieve those exceptions using Future.get, and presents three practical solutions—including try‑catch, Thread.setDefaultUncaughtExceptionHandler, and overriding afterExecute—to reliably capture and process thread‑pool errors.
This article demonstrates how to create a perpetual multithreaded Java task using a custom thread‑pool utility, supports concurrent execution of multiple long‑running jobs, and implements an elegant shutdown that drains remaining work before terminating.
This article explains the fundamentals of Java thread pools, covering their purpose, construction parameters, execution process, worker reuse, task retrieval with timeout, lifecycle states, shutdown methods, monitoring techniques, and practical guidelines for customizing thread pools in real-world projects.
This article explains why Java does not provide a forced stop for threads, demonstrates how to use interrupt and various ThreadPool shutdown methods—including shutdown, isShutdown, isTerminated, awaitTermination, and shutdownNow—to safely terminate threads, and provides practical code examples.
The article explains how converting a serial RPC call layer to an asynchronous parallel model can cause thread pool exhaustion and hunger lock when tasks depend on each other, demonstrates the issue with Java code, and provides practical strategies such as using separate pools or CompletableFuture to avoid the problem.
This comprehensive guide explores Java concurrency fundamentals, covering thread creation, lifecycle, synchronization mechanisms, lock implementations, thread-local storage, memory model, atomic classes, common concurrency utilities, and detailed explanations of thread pools, their configurations, states, and best practices, accompanied by over sixty interview-style questions and code examples.
Switching from single‑threaded synchronous calls to multithreaded asynchronous execution can boost performance, but it also introduces nine common problems—including missing return values, data loss, ordering issues, thread‑safety bugs, ThreadLocal anomalies, OOM, high CPU usage, transaction failures, and service crashes—that developers must understand and mitigate.
The article analyzes a production outage caused by misuse of ExecutorCompletionService, explains why missing take/poll leads to memory leaks, demonstrates correct and incorrect Java code examples, compares ExecutorService with ExecutorCompletionService, and provides practical guidelines to avoid similar OOM problems in backend services.
This article explains Java thread pools, covering their advantages, how to create and configure ThreadPoolExecutor, detailed parameter meanings, various built‑in pool types, usage examples, and best‑practice recommendations to avoid resource exhaustion in Java applications.
This article introduces asynchronous programming concepts in Java, explaining how multithreading, Future, FutureTask, CompletableFuture, and Spring's @Async annotation can transform synchronous workflows into high‑throughput, low‑latency solutions, with code examples and practical guidance for implementing each technique.
This article analyzes a production outage caused by misuse of ExecutorCompletionService, explains the underlying Java concurrency mechanisms, compares it with ExecutorService, provides correct code examples, and offers practical guidelines to avoid memory leaks and improve backend reliability.
This article explains the core concepts, configurable parameters, and execution workflow of Java's ThreadPoolExecutor, illustrating each setting with analogies, code examples, and step‑by‑step analysis to help developers design safe and efficient thread pools.
The article explains how improper use of java.lang.ThreadLocal in thread pools—failing to re‑initialize or clear values—can cause OOM, loss of implicit parameters, and data corruption, and provides recommendations for safe handling.
This article explains what MDC (Mapped Diagnostic Context) is, outlines its API and advantages, demonstrates common traceId loss problems in child threads and HTTP calls, and provides practical solutions including thread‑pool wrappers, MDC utilities, and interceptors for HttpClient, OkHttp, RestTemplate, and third‑party services, plus the required log pattern.
This article explains how ThreadPoolExecutor's execute and submit methods differ in exception handling, why execute may terminate a worker thread while submit silently swallows exceptions, and provides code examples and recommendations for proper error handling in Java concurrency.
The article explains how submitting tasks to ExecutorCompletionService without retrieving their results causes the internal unbounded LinkedBlockingQueue to retain Future objects, leading to memory leaks and OutOfMemoryError, and demonstrates the correct usage patterns to prevent this issue.
The article explains that CompletableFuture offers paired asynchronous methods—one using the default ForkJoinPool and another accepting a custom executor—and argues that providing an explicit thread pool avoids shared‑pool contention, loss of tracing information, ThreadLocal leakage, and class‑loader issues in Java backend applications.
This article explains how Java threads are created via the Thread.start method, details the underlying native implementation using pthread_create, compares Thread, Runnable, and Callable approaches, discusses the performance costs of spawning many threads, and presents thread‑pool optimization techniques for CPU‑ and I/O‑bound tasks.
This article explains how Python concurrency can boost program performance, covering multithreading, multiprocessing, the Global Interpreter Lock, thread safety, thread pools, and practical code examples for speeding up I/O‑bound and CPU‑bound tasks.
This article explains why InheritableThreadLocal fails in pooled threads, introduces Alibaba's TransmittableThreadLocal library, demonstrates how to wrap executors and rewrite code to correctly transmit ThreadLocal data across parent‑child threads in Java thread pools, and provides detailed implementation and usage examples.
This article explains how Java 8's CompletableFuture enables low‑overhead asynchronous composition, walks through its core methods, shows practical code examples for parallel data fetching, error handling, and task combination, and reveals implementation details from the source code.
The article explains how to handle multi‑table updates in a Spring Boot backend by replacing synchronous single‑threaded execution with three asynchronous strategies—using a ThreadPoolExecutor, Spring's @EnableAsync/@Async annotations, and a message‑queue decoupling—to improve response time and system stability.
This article compares several practical techniques—using isTerminated after shutdown, comparing task counts, employing CountDownLatch, maintaining a manual counter, and checking Future.isDone—to reliably determine when a Java ThreadPoolExecutor has completed all submitted jobs, complete with code examples and pros and cons for each method.
This article explains the purpose and implementation of Java's CompletionService, compares it with ExecutorService, shows how it retrieves task results in completion order, provides detailed source code analysis, and discusses typical use cases such as load‑balancing and fast‑result retrieval in concurrent applications.
The article explains how Java 8’s CompletableFuture enables efficient asynchronous programming—illustrated by Meituan’s order service refactor—by replacing slow synchronous RPC calls with composable, lazy, back‑pressure‑aware futures, offering thread‑pool best practices, robust exception handling, utility helpers, and achieving up to a 45 % latency reduction and fewer servers.
This article analyzes how replacing Java thread‑pool queues with the LMAX Disruptor framework dramatically improves CPU utilization, reduces tail latency, and lowers lock and CAS overhead, backed by detailed benchmarks, code examples, and real‑world deployment results from a high‑throughput feature service.
This article explores twelve practical multithreading use cases in Java, ranging from simple scheduled tasks and listeners to Excel imports, remote call aggregation, user context handling, MDC logging, high‑concurrency simulation, Kafka message processing, atomic counters, and delayed jobs, providing code examples and best‑practice tips for each scenario.
This article explains the purpose and usage rules of Spring's @Async annotation, compares built‑in executors, demonstrates how to enable @Async, and provides detailed examples of custom thread‑pool configurations, multiple pool management, and important source‑code analysis for robust asynchronous processing in Java backend applications.
Using ThreadLocal to store user information in Java web applications can lead to hidden failures such as loss of context and memory leaks, especially when thread pools are involved, so developers should restrict its usage to controller threads and employ static analysis tools to detect improper usage.
The article presents two 2018 incidents where improper Java thread‑pool settings caused service degradation and unavailability, analyzes the root causes such as insufficient core size, unbounded queues, and missing rejection handlers, and offers practical recommendations for dynamic sizing, alerting, degradation strategies, isolation, and auto‑scaling to prevent similar faults.
This article provides a comprehensive overview of Java concurrency topics, including various lock types, thread lifecycle states, differences between synchronized and Lock/ReentrantLock, thread safety, thread pool creation and customization, as well as practical multithreading use cases.
This article explains what MDC (Mapped Diagnostic Context) is, shows its API and advantages, demonstrates how to add interceptors and log patterns to include a traceId, and provides solutions for traceId loss in child threads and HTTP calls by wrapping thread pools and implementing HTTP client interceptors.
This article explains four practical techniques—using isTerminated, comparing task counts, CountDownLatch, and CyclicBarrier—to reliably detect when a Java ThreadPoolExecutor has finished executing all submitted tasks, including code examples, advantages, disadvantages, and a summary of each method.
This article explains what MDC (Mapped Diagnostic Context) is, its API and advantages, demonstrates how to integrate it into Spring MVC interceptors and log patterns, and provides solutions for traceId loss in child threads and HTTP calls using custom thread‑pool wrappers and HTTP client interceptors.
After upgrading a core component, a previously synchronous domain event in Spring became asynchronous, causing runtime errors; this article explains the underlying mechanism, shows the relevant source code of SimpleApplicationEventMulticaster, and clarifies how the presence or absence of a configured thread pool determines whether events are processed synchronously or asynchronously.
This article explains how to use Mapped Diagnostic Context (MDC) in Java logging frameworks to propagate traceId across threads and HTTP calls, covering API usage, advantages, common pitfalls, and practical solutions including interceptor implementation, thread‑pool wrappers, and client‑side interceptors for HttpClient, OkHttp, and RestTemplate.
This article reveals how creating a new thread pool for each @Async method in Spring can exhaust system resources, explains Spring Boot’s default executor behavior, shows code examples, and offers practical guidance to prevent thread‑pool related crashes in Java backend applications.
This article explains what MDC is, its API, common pitfalls like traceId loss in child threads and HTTP calls, and provides practical solutions using custom thread pool wrappers and interceptors for HttpClient, OkHttp, and RestTemplate to reliably propagate trace identifiers.
This article explains how to use a thread pool together with FutureTask to split a large query into many small asynchronous tasks, improving response speed and handling exceptions correctly in Java concurrent programming.
This article shares a detailed account of a backend engineer's multi‑stage interview process at Huanju (formerly YY), covering personal background, common Java and system design questions, database and caching strategies, distributed lock handling, and reflections on preparation and outcomes.
The article details how a SpringBoot image‑upload service suffered timeouts due to excessive Full GC and thread‑blockage, and explains the investigation, thread‑pool tuning, and the adoption of asynchronous Servlet (with Tomcat and Spring MVC implementations) to isolate long‑running URL‑download tasks while returning results synchronously.
This article introduces MDC, explains its API and benefits, and provides concrete solutions—including a thread‑pool wrapper and HTTP client interceptors—to reliably propagate traceId across threads and remote calls in Java backend applications.
This article explains why multiple Spring Boot timers can conflict due to single‑threaded execution, demonstrates the problem with example outputs, and shows how to configure a thread pool and use @Async annotations to run timers concurrently, preventing bottlenecks and avalanche effects.
This article explains the concept of MDC (Mapped Diagnostic Context) in Java logging, details its API, demonstrates how to propagate traceId across threads and HTTP calls using interceptors and custom thread‑pool wrappers, and shows how to configure log patterns to include the traceId.
This article explains the @Async annotation in Spring, how it enables asynchronous method execution, compares the built‑in executors, shows how to configure custom thread pools via AsyncConfigurer or AsyncConfigurerSupport, and provides code examples for void, Future and CompletableFuture based async methods.
This article introduces Java's CompletableFuture, compares it with the older Future API, demonstrates how to create, combine, and handle asynchronous tasks with code examples, and highlights best practices and pitfalls for effective concurrent programming.
This article introduces MDC, explains its API and advantages, and provides practical solutions for traceId propagation in multithreaded environments, HTTP calls, and custom thread pools using Java logging frameworks such as Log4j, Logback, and Log4j2.
This article explains what MDC is, the problems it faces such as traceId loss in child threads and HTTP calls, and provides concrete solutions including interceptor implementation, thread‑pool wrappers, and logging pattern adjustments to ensure reliable traceId propagation in Java backend services.
This article explains why Spring Boot's default single‑threaded scheduler can cause timer conflicts in real‑world applications and demonstrates how adding @Async annotations together with a custom ThreadPoolTaskExecutor configuration enables concurrent execution of multiple scheduled tasks.
To reduce response time when invoking multiple independent APIs, this article demonstrates how to refactor sequential Java calls into asynchronous executions using thread pools and CompletableFuture, providing complete code examples and performance comparisons.
This article explains how Youku tackled the large package size, thread‑explosion, and memory overhead introduced by integrating the Alipay mini‑program framework, using remote .so loading, layered dependency management, a unified thread pool, and lazy initialization to improve performance and stability.
This article explains how to create a fixed-size Java thread pool, attach a daemon thread that monitors the main thread, and use Phaser for synchronization, providing complete Groovy and Java examples with detailed code and console output.
This article explains how to use Java's FutureTask, Callable, and ExecutorService to run multiple API calls concurrently, aggregate their results, and dramatically reduce total response time compared with sequential execution, complete with code examples and performance analysis.
This article explains why and how to use asynchronous methods in Spring Boot to improve interface response speed, covering annotations, custom thread pools, exception handling, returning values, and practical considerations for backend development.
This article explains how to achieve Go‑style asynchronous execution in Java and Groovy by leveraging closures, the java.util.function.Supplier interface, custom thread‑pool wrappers, and Phaser‑based synchronization, complete with practical code examples and a custom ThreadFactory implementation.
This article compiles a comprehensive list of frequently asked Java interview questions, covering topics such as JDK/JRE/JVM relationships, object creation methods, equality comparison, concurrency mechanisms, collections, thread pools, and I/O models, providing concise answers for quick reference.
After a late‑night incident where a Dubbo 2.7.12 service crashed, the author traced high memory and CPU usage to a full GC spike, identified a HashedWheelTimer thread‑pool bug causing request timeouts to be missed, reproduced the leak, and confirmed the issue was fixed in Dubbo 2.7.13.
This article demonstrates how a Spring Boot thread pool behaves when its core size, max size, and queue capacity are exceeded by multiple asynchronous tasks, explains the resulting TaskRejectedException, and shows how to configure built‑in or custom rejection policies to handle such scenarios.
This article explains why uncaught exceptions cause thread pool threads to terminate, demonstrates experiments with execute and submit methods, and shows how catching exceptions or using Future.get() can preserve thread reuse in Java concurrency.
This article compares synchronous and various asynchronous approaches for invoking multiple third‑party services in a Spring Boot order‑creation workflow, demonstrating plain sequential calls, manual thread creation, thread‑pool execution, CompletionService handling, and CompletableFuture composition, and shows their performance impact through timing results.
This article explains how Spring's @Async annotation enables asynchronous method execution, compares synchronous and asynchronous flows, reviews the built‑in executors, highlights the drawbacks of the default SimpleAsyncTaskExecutor, and demonstrates how to configure a custom thread pool using AsyncConfigurer or TaskExecutor beans.
This article explains the concept, purpose, and internal workings of Java's ThreadPoolExecutor, covering thread lifecycle, pool creation parameters, common blocking queues, thread factories, rejection policies, and the execute() method with code examples to help developers efficiently manage concurrent tasks.
This guide explains how Spring's @Async annotation works, compares built-in executors, shows how to configure custom thread pools via AsyncConfigurer or AsyncConfigurerSupport, and demonstrates various async method signatures including void, Future and CompletableFuture with practical code examples.
This article introduces the various thread pool creation methods available in JDK 1.8—including fixed, cached, scheduled, single, single‑scheduled, and work‑stealing executors—explains their characteristics, provides sample Java code for each, and shows typical execution results.
This article explains the different blocking queue implementations—ArrayBlockingQueue, LinkedBlockingQueue, SynchronousQueue, and PriorityBlockingQueue—used by Java thread pools, describing their structures, behavior, fairness settings, and performance characteristics for concurrent task execution.
This article explains how to configure Spring Boot scheduled tasks, compare serial and parallel execution using @Async, create custom and global thread pools, and handle asynchronous exceptions, providing complete code examples and practical observations.
This article compares Java's Timer and ScheduledExecutorService for scheduling tasks, explains their internal workings, demonstrates common pitfalls, and provides multiple code examples showing how to schedule one‑off, fixed‑rate, and fixed‑delay tasks using both Runnable and Callable.
This guide explores why Java remains a top‑demand skill, offers practical advice on choosing the right JDK, explains keepAliveTime behavior in thread pools, and shares insider interview strategies from Alibaba experts to help developers secure offers.
This article explains how to write a concurrent unit test for the AssetService.update method using thread pools, CountDownLatch, AtomicInteger, and then suggests optimizations such as replacing AtomicInteger with LongAdder and employing CyclicBarrier to increase contention, providing full code examples and detailed explanations.
This article explains the concept of thread pools, their performance benefits, the three native Java pool implementations, detailed internal mechanisms of ThreadPoolExecutor, task queue choices, rejection policies, and practical tuning advice for real‑world applications such as Tomcat and custom frameworks.
This article explores the intricacies of Java's ThreadPoolExecutor, explaining how corePoolSize=0, thread creation, core thread timeout, keepAliveTime settings, exception handling, shutdown strategies, Spring equivalents, and provides practical best‑practice recommendations with code examples.
This article explains the nuances of ThreadPoolExecutor configuration in Java, covering the behavior of corePoolSize=0, core thread creation, termination policies, keepAliveTime effects, exception handling, shutdown strategies, Spring alternatives, and practical best‑practice recommendations for robust backend concurrency management.
This article explains how ThreadLocal works in Java, demonstrates how improper use can cause Out‑Of‑Memory errors, analyzes the underlying cause in ThreadLocalMap, and provides a simple fix by invoking remove() after use to avoid memory leaks.
This article explains the purpose and design of Java thread pools, illustrates common pitfalls such as unbounded queues causing OutOfMemoryError, and provides practical guidelines for configuring bounded queues, naming threads, handling exceptions, choosing rejection policies, and using separate pools for compute‑intensive tasks.
This article systematically explains why thread pools are needed, how to create them, the types of pools Executors can build, key parameters, underlying principles, rejection policies, blocking queues, core‑thread settings, pool states, thread reuse, the difference between submit() and execute(), and practical usage tips for Java developers.
This article explains the differences between user threads and daemon (background) threads in Java, demonstrates how to identify, create, and configure them—including thread pools—and discusses important considerations, priority effects, and typical use cases such as garbage collection.
Explore deep Java concurrency concepts, from HashMap internals and its JDK7/JDK8 differences to ConcurrentHashMap’s lock strategies, thread states, memory models, volatile, CAS, synchronized, thread pools, AQS, and common interview questions, providing comprehensive insights for mastering multithreaded programming.
This article explains the inner workings of Java thread pools, clarifies common misconceptions about core pool sizing, BlockingQueue behavior, concurrency calculation, and runtime factors such as GC, providing practical guidance and code examples for correctly configuring thread pools in backend systems.