Java.Multithreading. if i use ForkJoin is it guaranteed to solve each task on different core ?

❌ No, not guaranteed, but ✅ it is highly optimized and designed to do so — more than ThreadPoolExecutor.

Let’s break this down 👇

Continue reading →
Posted in Без рубрики | Comments Off on Java.Multithreading. if i use ForkJoin is it guaranteed to solve each task on different core ?

Java.Multithreading.If i use ThreadPoolExecutor, may it be possible that tasks will be executed on different cores ?

yes, if you use a ThreadPoolExecutor, it is possible and very likely that your tasks will be executed on different CPU cores, depending on how many threads your executor runs and how many cores are available.

Let’s break it down 🔧👇

Continue reading →
Posted in Без рубрики | Comments Off on Java.Multithreading.If i use ThreadPoolExecutor, may it be possible that tasks will be executed on different cores ?

Java.Multithreading.What is the difference between “concurrency” and “parallelism”?

🧠 Quick Definition:

TermDefinition
ConcurrencyDealing with lots of tasks at once (not necessarily simultaneously)
ParallelismActually doing lots of tasks at the same time
Continue reading →
Posted in Без рубрики | Comments Off on Java.Multithreading.What is the difference between “concurrency” and “parallelism”?

Java.Multithreading.What is “thread safety”?

🔐 What Is Thread Safety?

Thread safety means:

A piece of code or a data structure behaves correctly when accessed by multiple threads at the same time, without causing:

  • data corruption,
  • race conditions,
  • unexpected behavior.

In simple terms: It works as expected no matter how many threads use it simultaneously.

Continue reading →
Posted in Без рубрики | Comments Off on Java.Multithreading.What is “thread safety”?

Java.Multithreading.HappensBeforeExample

public class HappensBeforeExample {
    static int data = 0;
    static volatile boolean ready = false;

    public static void main(String[] args) {
        Thread writer = new Thread(() -> {
            data = 42;        // Step 1
            ready = true;     // Step 2 — volatile write, gurantees to be in main memory
        });

        Thread reader = new Thread(() -> {
            while (!ready) {
                // spin until ready becomes true
            }
            System.out.println("Data = " + data); // Step 3 — guaranteed to print 42
        });

        writer.start();
        reader.start();
    }
}
Continue reading →
Posted in Без рубрики | Comments Off on Java.Multithreading.HappensBeforeExample

Java.Multithreading.What is main main memory, is it heap ?

🧠 What is “Main Memory” in the Java Memory Model?

In the context of the Java Memory Model (JMM), main memory refers to the shared memory area where all variables (especially instance fields, static fields, and array elements) reside and are visible to all threads.

✅ It’s the memory that all working memory (thread-local caches) synchronize with.

Continue reading →
Posted in Без рубрики | Comments Off on Java.Multithreading.What is main main memory, is it heap ?

Java.Multithreading.Explain the Java memory model?

The Java Memory Model (JMM) defines how threads interact through memory — specifically, how changes to variables made by one thread become visible to others.

It’s part of the Java Language Specification and is enforced by the Java Virtual Machine (JVM) to ensure consistent behavior across all platforms.

Continue reading →
Posted in Без рубрики | Comments Off on Java.Multithreading.Explain the Java memory model?

Java.Serialization.JSON.XML

🚀 While Java’s built-in binary serialization (Serializable) is powerful, you often want to serialize objects to readable and interoperable formats like JSON, XML, or YAML, especially for:

  • APIs
  • Config files
  • Cross-platform communication (e.g., Java ↔ Python)

Let’s walk through the popular formats and tools 👇

Continue reading →
Posted in Без рубрики | Comments Off on Java.Serialization.JSON.XML

Java.Serialization.What are the ways to control the values ​​of the deserialized object

🔧 1. Use a Custom readObject() Method

This is the standard way to hook into deserialization:

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject(); // Restore default values

    // 💡 Customize here
    if (age < 0) age = 0; // Validation
    if (nickname == null) nickname = "Anonymous";
}
Continue reading →
Posted in Без рубрики | Comments Off on Java.Serialization.What are the ways to control the values ​​of the deserialized object

Java.Serialization.What is the problem with Singleton serialization?

🧠 What’s a Singleton?

A Singleton ensures that a class has only one instance in the JVM:

public class Singleton implements Serializable {
    private static final Singleton INSTANCE = new Singleton();
    private Singleton() {}

    public static Singleton getInstance() {
        return INSTANCE;
    }
}

✅ So when you do:

Singleton s1 = Singleton.getInstance();
Singleton s2 = Singleton.getInstance();
System.out.println(s1 == s2); // true ✅
Continue reading →
Posted in Без рубрики | Comments Off on Java.Serialization.What is the problem with Singleton serialization?