When the thread pool queue is full and a new task is submitted, what happens depends on the thread pool’s rejection policy.
Let’s break it down clearly 👇
Continue readingWhen the thread pool queue is full and a new task is submitted, what happens depends on the thread pool’s rejection policy.
Let’s break it down clearly 👇
Continue readingThe optimal thread pool size depends on several factors, mainly the type of tasks your application runs and the hardware it runs on.
Continue readingA thread pool is a programming construct used to manage a group of worker threads for executing tasks concurrently. Instead of creating and destroying a thread for each task (which is expensive), a thread pool reuses a fixed number of threads to execute many tasks efficiently
Continue readinginterrupted() vs isInterrupted()| Method | Static? | Clears Interrupt Flag? | Checks Which Thread? |
|---|---|---|---|
Thread.interrupted() | ✅ Yes | ✅ Yes (resets to false) | Current thread only |
isInterrupted() | ❌ No | ❌ No | Any specific thread object |
run():Thread.stop() is deprecated and strongly discouraged because it’s unsafe, unpredictable, and can corrupt program state.
Let me explain why in a clear, structured way.
Continue reading❌ Deprecated (DO NOT USE)
thread.stop(); // 🚫 Dangerous and deprecated
This kills the thread immediately — which can leave shared data in an inconsistent state.
It doesn’t give the thread a chance to clean up resources or release locks.
Continue readingwe use smth like this in Counter class
AtomicInteger counter = new AtomicInteger(0);
counter.incrementAndGet();
👉 We don’t directly call compareAndSet() — but under the hood, incrementAndGet() uses compareAndSet() (or CAS instructions) internally!
CAS is a hardware-level atomic operation used to implement lock-free synchronization.
It works like this:
expected).Yes, there are multiple ways to solve a race condition depending on what you’re doing and how critical performance is.
Let’s go over the most common and effective ways 🔧:
Continue reading