Java Threads and Concurrency Flashcards
6 cards from real SCJP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 6 Java Threads and Concurrency flashcards as text
What does the `volatile` keyword guarantee for a variable in Java?
Answer: Visibility — all threads see the most recent write to the variable
`volatile` ensures that reads and writes to a variable go directly to main memory, guaranteeing visibility of changes across threads.
Which method is used to start a thread's execution in Java?
Answer: start()
Calling `start()` on a `Thread` object creates a new OS thread and schedules the `run()` method for execution.
What is a race condition in Java concurrency?
Answer: Unpredictable behavior caused by multiple threads accessing shared data without proper synchronization
A race condition occurs when the program's outcome depends on the non-deterministic ordering of unsynchronized thread operations.
Which Java class provides a thread-safe, atomic integer that supports compound operations like increment?
Answer: AtomicInteger
`AtomicInteger` in `java.util.concurrent.atomic` provides atomic compound operations like `incrementAndGet()` without explicit synchronization.
In Java, which method pair is used for inter-thread communication?
Answer: notify() and wait()
`wait()` and `notify()` (with `notifyAll()`) on an `Object` are used for coordinating thread communication through a shared monitor.
What is the role of the `Executor` framework in Java concurrency?
Answer: To manage and reuse thread pools, decoupling task submission from execution
The `Executor` framework (in `java.util.concurrent`) manages thread pools, allowing efficient task submission without manual thread lifecycle management.
How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Not reviewed by a subject-matter expert. Editorial policy