Urgent.News

What's breaking now, across thousands of outlets.

Tech

Java Concurrency & Multithreading: 40 Interview Questions

1. Process vs Thread A process has its own memory space and OS resources; threads live inside a process and share its heap and file handles but keep their own stack and program counter. That shared memory is exactly why threads are cheap to create but dangerous to coordinate - every thread can see and corrupt the same data. 2. Platform Thread vs Virtual Thread A platform thread maps 1:1 to an OS…

Java Concurrency and Multithreading: 40 Interview Questions

A process has its own memory space and OS resources, while threads live inside a process and share its heap and file handles, but maintain their own stack and program counter. This shared memory is why threads are cheap to create but dangerous to coordinate, as every thread can see and potentially corrupt the same data.

Java offers two types of threads: platform threads, which map one-to-one with OS threads and are expensive to create, and virtual threads (Project Loom, introduced in Java 21), which are lightweight threads managed by the JVM and can be spawned in the thousands. Virtual threads run on a small pool of carrier OS threads, unmounting from their carrier when blocked on I/O to allow another virtual thread to run.

The Java Memory Model (JMM) defines visibility guarantees for shared state between threads, accounting for compiler and CPU reordering and per-core caching. Volatile, synchronized, and final fields provide visibility guarantees for Java threads.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Your daily reminder needs three states, not a boolean

I built a checklist that opens itself at 8 am. The hard part wasn't opening it. It was working out when to stop. The version that fails The obvious model is a boolean.

  • The author builds a checklist app opening at 8 am.
  • Initially uses boolean flag to track window state.
  • Introduces third state for answered but not closed windows.

More from Sunday 20 September →