CONCURRENCY / NOTES</>↗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 / NOTES</>↗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 / NOTES</>↗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 / NOTES</>↗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 = […]
CONCURRENCY / NOTES</>↗Concurrency12 Nov 2025
CompletableFuture is a powerful tool in Java to implement asynchronous programming. It allows you to perform tasks in the background, chain multiple async tasks together, handle both success and failure scenarios, and combine multiple async computations. Here’s a summary of how to use CompletableFuture with examples: 1. Run a task asynchronously Use supplyAsync() (if the […]
LANG PACKAGE / NOTES</>↗Lang Package12 Nov 2025
The Virtual Threads API is part of Project Loom in the Java platform. With Java 19, virtual threads became available as a preview feature, enabling the creation of lightweight threads that can run concurrently. They work similarly to traditional threads but are much cheaper in terms of memory and thread management because they are managed […]