CONCURRENCY / CATATAN</>↗Concurrency14 Mei 2025
Asynchronous pipelines can be implemented efficiently in Java using CompletableFuture. The ability of CompletableFuture to chain multiple steps through its functional programming model (e.g., thenApply, thenCompose, thenAccept, etc.) makes it a powerful tool for building non-blocking pipelines. Here’s a step-by-step guide to implement async pipelines using CompletableFuture chaining: 1. Basics of CompletableFuture CompletableFuture is a […]
CONCURRENCY / CATATAN</>↗Concurrency13 Mei 2025
Using CompletableFuture in Java can be a powerful way to implement reactive-style concurrency. It provides a clean and functional way to perform asynchronous tasks, compose their results, and handle exceptions without blocking threads. Here’s an explanation with examples to guide you through its reactive-style usage: Key Features of CompletableFuture Asynchronous execution – Run tasks on […]
CONCURRENCY / CATATAN</>↗Concurrency13 Mei 2025
Managing thread-local state in a highly concurrent environment requires an understanding of ThreadLocal in Java and certain best practices to ensure correctness and good performance. Here’s how you can effectively manage thread-local state: 1. Use ThreadLocal for Thread-Specific State The ThreadLocal class provides thread-local variables. Each thread accessing such a variable gets its own, independent […]
JSCH / CATATAN</>↗JSch12 Mei 2025
When working with JSch (Java Secure Channel) for SSH connections, handling interactive prompts and keyboard-interactive authentication requires implementing the UserInfo and UIKeyboardInteractive interfaces provided by JSch. These interfaces allow you to interact with the user to gather necessary input for authentication (like passwords, passphrases, or other interactive challenges like 2FA). Here’s a step-by-step process: Steps […]
CONCURRENCY / CATATAN</>↗Concurrency12 Mei 2025
Designing non-blocking algorithms with ConcurrentLinkedQueue can be a powerful way to build high-performance concurrent applications. ConcurrentLinkedQueue is a thread-safe, non-blocking queue implementation based on a lock-free linked node algorithm. It uses atomic operations (through sun.misc.Unsafe or java.util.concurrent.atomic package underneath) to ensure thread safety without locking, making it highly scalable. Here’s how to approach the design […]
CONCURRENCY / CATATAN</>↗Concurrency12 Mei 2025
The StampedLock class in Java’s concurrency utilities (introduced in Java 8) is a high-performance read/write lock that differs from traditional ReadWriteLock (like ReentrantReadWriteLock) due to its ability to provide three locking modes: Write Lock: Exclusive access. Read Lock: Shared (non-exclusive) access. Optimistic Read Lock: A lightweight, non-blocking read lock for scenarios where reads dominate writes, […]