CONCURRENCY / NOTES</>↗Concurrency13 May 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 / NOTES</>↗JSch12 May 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 / NOTES</>↗Concurrency12 May 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 / NOTES</>↗Concurrency12 May 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, […]
JSCH / NOTES</>↗JSch11 May 2025
Integrating JSch with a custom logging framework to facilitate SSH auditing involves capturing and routing pertinent log information about SSH connections, commands, and activities into your custom logging mechanism. Below are the steps and considerations to achieve this: 1. Set a Custom Logger for JSch JSch allows integration with custom loggers by implementing the com.jcraft.jsch.Logger […]
CONCURRENCY / NOTES</>↗Concurrency11 May 2025
Optimizing task-splitting strategies in RecursiveTask (a subclass of the ForkJoin framework in Java) is crucial for improving performance and minimizing inefficiencies like excessive overhead or poor parallelism. Here are some strategies and tips to achieve efficient task splitting: 1. Choose an Optimal Threshold The optimal threshold (commonly called a “granularity threshold”) determines when you should […]