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

Java.Multithreading.Can new instances of a class be created while a static synchronized method is executing?

Yes, new instances of a class can be created while a static synchronized method is executing. Let’s break it down: 🔒 static synchronized method It locks on the Class object, not on an instance. So, if thread A is executing … Continue reading →

Posted in Без рубрики | Comments Off on Java.Multithreading.Can new instances of a class be created while a static synchronized method is executing?

Java.Multithreding.What states can a thread be in?

Let’s walk through the 6 thread states in Java, according to the java.lang.Thread.State enum. 🧵 Java Thread States State When It Happens NEW Thread object is created, but start() has not been called RUNNABLE Thread is ready to run or … Continue reading →

Posted in Без рубрики | Comments Off on Java.Multithreding.What states can a thread be in?

Java.Multithreading.Example with consumer and producer

Let’s compare wait()/notify() (used with synchronized) and Condition (used with ReentrantLock) — both are used for thread coordination, but Condition gives you more flexibility. We’ll walk through: A wait()/notify() example A Condition example doing the same thing Scenario: We have … Continue reading →

Posted in Без рубрики | Comments Off on Java.Multithreading.Example with consumer and producer

Java.Multithreading.When to use what ?

🔎 Key Criteria to Decide: Do you need mutual exclusion? Do you need only visibility or atomicity? Do you need fine-grained locking or advanced features like try-lock, fairness, etc.? Are threads coordinating around a condition (like a signal or phase)? … Continue reading →

Posted in Без рубрики | Comments Off on Java.Multithreading.When to use what ?

Java.Multithreading.What are the different types of synchronization in Java?

🧠 1. Intrinsic (Built-in) Synchronization This is the most commonly used type of synchronization in Java, based on monitors. A. Synchronized Method Locks on the current object (this) For static methods, it locks on the class object (ClassName.class)

Posted in Без рубрики | Comments Off on Java.Multithreading.What are the different types of synchronization in Java?

Java.Multithreading.Define the concept of “synchronization”.

🧠 What is Synchronization? Synchronization is the process of controlling access to shared resources by multiple threads to prevent race conditions, data inconsistency, and memory visibility issues.

Posted in Без рубрики | Comments Off on Java.Multithreading.Define the concept of “synchronization”.

Java.Multithreading.if you say monitor is the mutex, tell me in terms of mutex how sync happens ?

💡 First: A Monitor in Java = A Mutex + Condition Variable Java’s monitor is not just a lock — it’s a synchronization mechanism that includes: a mutex (for mutual exclusion) zero or more condition queues (for waiting/notification: wait(), notify())

Posted in Без рубрики | Comments Off on Java.Multithreading.if you say monitor is the mutex, tell me in terms of mutex how sync happens ?

Java.Multithreading.Give me details about monitor, i cannot understand how it can synchronize only part of the method if we locking whole the object ?

🧠 First, What Is a Monitor? A monitor is a mutex (mutual exclusion lock) + condition variable attached to every object in Java. Every Java object has one monitor. A monitor ensures that only one thread at a time can … Continue reading →

Posted in Без рубрики | Comments Off on Java.Multithreading.Give me details about monitor, i cannot understand how it can synchronize only part of the method if we locking whole the object ?

Java.Multithreading.Why do we need Synchronized (this) and Synchronized method if they give us the same result ?

Let’s unpack it carefully — the short answer is: ✅ they behave the same, but 🚀 give you flexibility in different contexts.

Posted in Без рубрики | Comments Off on Java.Multithreading.Why do we need Synchronized (this) and Synchronized method if they give us the same result ?

Java.Multithreading.What is a “monitor” in Java?

🧠 What Is a Monitor in Java? A monitor is a synchronization construct that allows threads to have mutually exclusive access to critical sections of code or data. In Java, every object has an implicit monitor — yes, even a … Continue reading →

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