CONCURRENCY / CATATAN</>↗Concurrency26 Des 2025
Creating a custom thread factory in Java is a powerful way to manage how threads are initialized. Instead of using the default factory, you can customize thread names (vital for debugging!), set priority levels, or even create daemon threads. To do this, you need to implement the java.util.concurrent.ThreadFactory interface. 1. Implement the ThreadFactory Interface The […]
CONCURRENCY / CATATAN</>↗Concurrency25 Des 2025
Hello! ExecutorService.invokeAll is a powerful method when you have a collection of tasks and need to wait until every single one of them finishes before moving forward. Here’s a breakdown of how it works and how to use it effectively. What does invokeAll do? Executes a collection of tasks: It takes a Collection of Callable<T> […]
CONCURRENCY / CATATAN</>↗Concurrency24 Des 2025
Using ThreadLocal safely is crucial because, while it provides a way to store data that is accessible only by a specific thread, it can easily lead to memory leaks and unexpected behavior in environments that use thread pools (like Spring MVC or Jakarta EE). Here is how to use it safely in your Java applications. […]
CRYPTOGRAPHY / CATATAN</>↗Cryptography21 Des 2025
Atomic variables in java.util.concurrent.atomic are designed for lock-free, thread-safe operations on single variables. They leverage low-level CPU instructions like Compare-And-Swap (CAS) to ensure data consistency without the overhead of synchronized blocks. Here’s a guide on how to use the most common atomic classes. 1. AtomicInteger and AtomicLong These are used for numeric counters or IDs. […]
CONCURRENCY / CATATAN</>↗Concurrency20 Des 2025
In Java, both synchronized and ReentrantLock are used to manage thread safety, but they offer different levels of control and flexibility. 1. synchronized Keyword The synchronized keyword is the built-in mechanism in Java for mutual exclusion. It is simpler to use because the JVM automatically handles acquiring and releasing the lock. Usage: Can be applied […]
CONCURRENCY / CATATAN</>↗Concurrency19 Des 2025
A CountDownLatch is a synchronization aid that allows one or more threads to wait until a set of operations being performed in other threads completes. It’s initialized with a given count, and the await() methods block until the current count reaches zero due to invocations of the countDown() method. Here is a practical guide on […]