Author: Editorial Team
-
Java Stream program to find all even numbers from a list
Approach 1 Approach 2 Using Collectors.partitioningBy() – To classify into even and odd Approach 3
-
Why is CompletableFuture Preferred Over Plain Threads in Microservices?
In modern microservice architectures, asynchronous programming plays a critical role in building scalable, responsive, and resource-efficient systems. While Java allows you to create threads using the Thread class or Runnable interface, using CompletableFuture is often the preferred approach in microservices. This tutorial explains why CompletableFuture is preferred over plain threads with in-depth comparisons, real-world use…
-
Difference Between volatile and AtomicReference in Java
1. Introduction to volatile 1.1. Definition The volatile keyword in Java is used to mark a variable as being shared among threads. It ensures that all reads and writes to that variable go directly to and from main memory (RAM), not CPU cache. 1.2. Key Properties 1.3. Syntax Although count is volatile, count++ is not…
-
How Does Java Handle False Sharing in Concurrency?
1. Introduction In modern multi-threaded Java applications, performance issues may arise from subtle low-level hardware behavior. One such issue is false sharing — a CPU cache-related performance bottleneck. This tutorial explores what false sharing is, how it impacts Java concurrency, and how Java handles or mitigates it, especially through memory padding and Java 8+ features.…
-
ScheduledThreadPoolExecutor in Java
1. What is a ScheduledThreadPoolExecutor? ScheduledThreadPoolExecutor is a part of Java’s java.util.concurrent package. It allows you to schedule tasks to run after a delay or periodically, using a pool of threads. It is a powerful replacement for the older Timer and TimerTask classes, offering: 2. Where is it defined? It implements: 2. Why use ScheduledThreadPoolExecutor…
