CONCURRENCY / CATATAN</>↗Concurrency08 Mei 2025
Building a work-stealing pool using the ForkJoinPool in Java is straightforward, as the ForkJoinPool class natively supports the work-stealing mechanism. Work-stealing allows idle threads to “steal” tasks from the queues of other busy threads, increasing the efficiency of the processing. Here’s how you can create and use a work-stealing pool with ForkJoinPool: 1. Understanding ForkJoinPool […]
KOTLIN / CATATAN</>↗Kotlin08 Mei 2025
In Kotlin, the safe call operator (?.) is used to handle nullable types safely. It ensures that the property or method is accessed only if the value is non-null, avoiding the possibility of a NullPointerException. Here’s how it works: Syntax and Usage: The ?. operator allows you to safely access a property or call a […]
KOTLIN / CATATAN</>↗Kotlin08 Mei 2025
In Kotlin, the when expression can be used as an alternative to the traditional switch statement found in languages like Java. The when expression is versatile, concise, and supports a wide range of matching conditions. Here’s how you can use it: Examples of Using the when Expression Using when as a simple switch: fun getResponse(code: […]
CONCURRENCY / CATATAN</>↗Concurrency08 Mei 2025
To throttle concurrent threads using ThreadPoolExecutor settings in Java, you can configure its key parameters: core pool size, maximum pool size, and queue capacity. These settings control how ThreadPoolExecutor manages the number of concurrently running threads and queued tasks. Explanation of Key ThreadPoolExecutor Settings: Core Pool Size: This defines the number of threads that are […]
CONCURRENCY / CATATAN</>↗Concurrency07 Mei 2025
To process tasks as they complete using a CompletionService in Java, you can take advantage of the ExecutorCompletionService. This class provides a mechanism to submit tasks for execution and retrieve their results in the order of completion, rather than the order of submission. Key Steps for Using CompletionService: Create an ExecutorService: This handles the thread […]
CONCURRENCY / CATATAN</>↗Concurrency07 Mei 2025
To cancel long-running tasks in an ExecutorService, you can use the Future object returned when you submit a task and invoke its cancel method. Below are the steps and some important considerations for canceling tasks: 1. Submit Tasks to the ExecutorService When you submit a task to an ExecutorService, it returns a Future object that […]