Java / Java Concurrency and Multi Threading in Java 17 and Java 21 Interview questions
What is a thread in Java?
A thread is the smallest independently schedulable unit of execution inside a process. Every thread has its own call stack, program counter, and local variables, but it shares the process's heap memory, open files, and static fields with every other thread in that same JVM.
In Java, a thread is represented by an instance of java.lang.Thread. Every running Java program has at least one thread automatically, the main thread, which executes the main() method.
Because threads share memory, multiple threads can read and write the same object concurrently. That's what makes multithreading powerful for parallel work, but it's also why shared mutable state needs explicit coordination through locks, atomics, or immutable design.
More Related questions...