Question 1
Which of the following is the primary difference between a lock and a monitor in Java?
A lock is used to block threads, while a monitor allows concurrent thread execution
A lock requires manual release, while a monitor automatically releases the lock
A lock is used for low-level memory management, while a monitor is used for thread management
There is no difference; they are interchangeable terms
Question 2
Which of the following is true about thread safety in Java?
Thread safety ensures that a class or method is accessed by one thread at a time
Thread safety is irrelevant in Java
Only one thread can run in a program at any time
Thread safety is only needed for high-performance applications
Question 3
Which method can be used to ensure thread safety in Java?
Using the volatile keyword
Using synchronized blocks
Using locks like ReentrantLock
All of the above
Question 4
Which of the following describes a monitor in Java?
A monitor allows synchronized access to a block of code by multiple threads
A monitor is a type of thread pool
A monitor ensures that only one thread can access a shared resource at a time
A monitor prevents race conditions
Question 5
What is the ReentrantLock class used for?
To ensure thread safety without using synchronized blocks
To allow multiple threads to acquire the lock simultaneously
To prevent deadlock situations
To execute threads in parallel
Question 6
What does ThreadLocal provide in Java?
It provides a separate copy of variables for each thread
It ensures only one thread accesses a resource at a time
It allows threads to share data safely
It controls the number of threads running
Question 7
Which of the following best describes thread safety?
Multiple threads can access the same resource simultaneously without causing errors
Only one thread can access the resource at any time
Threads are not allowed to access shared resources
Threads execute in parallel without synchronization
Question 8
Which of the following does NOT guarantee thread safety?
Synchronization
Using ReentrantLock
Using ThreadLocal
Using multiple threads in parallel
Question 9
What is the benefit of using ReentrantLock over synchronization?
ReentrantLock allows for more complex lock management and provides advanced features like try-lock
ReentrantLock is faster than synchronized
ReentrantLock allows multiple threads to execute concurrently
None of the above
Question 10
What does thread safety ensure in Java?
Only one thread can access a class or method at a time
Threads can run independently without interference
Threads run simultaneously without synchronization
No thread can access a shared resource
There are 10 questions to complete.