Category Archives: Без рубрики

Java.Multithreading.What happens if the thread pool queue is already full but a new task is submitted?

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 👇

Posted in Без рубрики | Comments Off on Java.Multithreading.What happens if the thread pool queue is already full but a new task is submitted?

Java.Multithreading.How big should a thread pool be?

The optimal thread pool size depends on several factors, mainly the type of tasks your application runs and the hardware it runs on.

Posted in Без рубрики | Comments Off on Java.Multithreading.How big should a thread pool be?

Java.Multithreading.What is a thread pool?

A 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 … Continue reading →

Posted in Без рубрики | Comments Off on Java.Multithreading.What is a thread pool?

Java.Multithreding.What is the difference between interrupted() and isInterrupted()?

🧠 interrupted() 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

Posted in Без рубрики | Comments Off on Java.Multithreding.What is the difference between interrupted() and isInterrupted()?

Java.Multithreding.What happens when an exception is thrown in a thread?

✅ 1. If it’s a checked or unchecked exception thrown from run(): The thread terminates immediately. The exception is not rethrown to the main thread. If uncaught, it’s passed to the thread’s UncaughtExceptionHandler (if any).

Posted in Без рубрики | Comments Off on Java.Multithreding.What happens when an exception is thrown in a thread?

Java.Multithreading.Why is it not recommended to use Thread.stop()?

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.

Posted in Без рубрики | Comments Off on Java.Multithreading.Why is it not recommended to use Thread.stop()?

Java.Multithreading.How to stop a thread?

❌ Deprecated (DO NOT USE) 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.

Posted in Без рубрики | Comments Off on Java.Multithreading.How to stop a thread?

Java.Multithreading.In Counter class we dont use compareAndSet method, so how it works ?

we use smth like this in Counter class 👉 We don’t directly call compareAndSet() — but under the hood, incrementAndGet() uses compareAndSet() (or CAS instructions) internally!

Posted in Без рубрики | Comments Off on Java.Multithreading.In Counter class we dont use compareAndSet method, so how it works ?

Java.Multithreading.How CAS works under the hood and how it helps in sychronization ?

🔁 What is CAS (Compare-And-Swap)? CAS is a hardware-level atomic operation used to implement lock-free synchronization. It works like this: Read the current value of a variable (expected). Compare it to an expected value. If it matches, swap it with … Continue reading →

Posted in Без рубрики | Comments Off on Java.Multithreading.How CAS works under the hood and how it helps in sychronization ?

Java.Multithreading.Is there a way to solve a race condition?

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 🔧:

Posted in Без рубрики | Comments Off on Java.Multithreading.Is there a way to solve a race condition?