CodeStudy.net
Toggle Menu
Home
Online Java Compiler
Tutorials
Java Tutorial
Python Tutorial
SQL Database Design
Blog
All Posts
Multithreading and Concurrency in Java
Test your understanding of threads,synchronization,and concurrency utilities.
1. Which interface should be implemented to create a thread in Java when extending Thread is not preferred?
Runnable
Callable
Executable
Threadable
2. What does the 'synchronized' keyword in Java ensure for a method?
Atomicity only
Visibility only
Ordering only
Atomicity, Visibility, and Ordering
3. Which method is used to make a thread wait for another thread to complete execution?
wait()
join()
sleep()
yield()
4. What is the result type of the Runnable interface's run() method?
void
Object
Thread
boolean
5. Which class represents the result of an asynchronous computation in Java?
Future
Callable
Promise
Task
6. Which of the following is NOT a thread state in Java?
NEW
RUNNING
BLOCKED
TERMINATED
7. What is the primary purpose of the volatile keyword in Java?
Ensure atomicity of compound operations
Prevent instruction reordering and ensure visibility
Create a daemon thread
Synchronize method execution
8. What determines the default priority of a newly created thread in Java?
Always 5
The parent thread's priority
The JVM's default (10)
The system clock
9. Which methods throw InterruptedException when a thread is interrupted? (Select all that apply)
Thread.sleep(long)
Object.wait()
Thread.join()
Thread.yield()
Thread.start()
10. Which of the following are thread-safe collections? (Select all that apply)
ArrayList
ConcurrentHashMap
CopyOnWriteArrayList
HashMap
ConcurrentLinkedQueue
11. Which components are part of Java's Executor Framework? (Select all that apply)
ThreadPoolExecutor
ScheduledExecutorService
Executors
Runnable
Callable
12. Which conditions are necessary for a deadlock to occur? (Select all that apply)
Mutual Exclusion
Hold and Wait
No Preemption
Circular Wait
High CPU Usage
13. Which of the following are valid uses of the synchronized keyword? (Select all that apply)
Synchronized methods
Synchronized static methods
Synchronized blocks
Synchronized variables
Synchronized constructors
14. The volatile keyword guarantees atomicity for increment operations like i++.
True
False
15. A thread in the BLOCKED state is waiting to acquire a monitor lock.
True
False
16. ThreadLocal provides thread-safe access by sharing a single variable across threads.
True
False
17. Calling Object.wait() releases the object's monitor lock.
True
False
18. Name the interface that declares the call() method, which returns a value and may throw checked exceptions.
19. What method is used to wake all threads waiting on an object's monitor?
20. What is the common abbreviation for the Java concurrency utilities package (e.g., containing ConcurrentHashMap)?
Reset
Answered 0 of 0 — 0 correct