CONCURRENCY / CATATAN</>↗Concurrency19 Des 2025
In Java’s concurrency utilities, CyclicBarrier is a synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point. It is called “cyclic” because it can be re-used after the waiting threads are released. Here is a breakdown of how to use it effectively. 1. Basic Concepts […]
CONCURRENCY / CATATAN</>↗Concurrency29 Nov 2025
Semaphore is an advanced synchronization mechanism used to control access to a shared resource by multiple threads. It can maintain a set of permits, restricting how many threads can concurrently access a critical section or shared resource. If the permits are exhausted, additional threads will block until permits are released. How to Use Semaphore for […]
CONCURRENCY / CATATAN</>↗Concurrency23 Nov 2025
ForkJoinPool in Java is a part of the java.util.concurrent package and is designed to efficiently execute recursive tasks using a work-stealing algorithm. It works particularly well for problems that can be split into smaller subproblems and then combined to form the final result, adhering to the divide-and-conquer paradigm. Here’s how you can use ForkJoinPool for […]
CONCURRENCY / CATATAN</>↗Concurrency22 Nov 2025
To schedule tasks using ScheduledExecutorService in Java, follow these steps: 1. Create a ScheduledExecutorService Use Executors.newScheduledThreadPool(int corePoolSize) to get an instance of ScheduledExecutorService. corePoolSize: Number of threads to keep in the pool. 2. Schedule Tasks The ScheduledExecutorService provides three methods for scheduling tasks: schedule: Schedule a task to run after a specific delay. scheduler.schedule(() -> […]
CONCURRENCY / CATATAN</>↗Concurrency16 Nov 2025
To use ExecutorService with virtual threads in Java, you can leverage the Executors.newVirtualThreadPerTaskExecutor() method. This method creates an ExecutorService where each task is executed on a new virtual thread, managed by the Java runtime. Here’s a step-by-step guide: 1. Dependencies & Setup Ensure you are using Java 19 or newer. Virtual threads were introduced as […]
CONCURRENCY / CATATAN</>↗Concurrency14 Nov 2025
To combine multiple CompletableFuture objects in Java, you can use the following approaches, depending on your specific use case: 1. Combine Two Futures If you have two CompletableFuture instances and need to combine their results, use the thenCombine method. It lets you specify how to merge the results of both futures. Example: CompletableFuture<String> future1 = […]