Java Programming — Multithreading
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 21–30 of 100 questions in Multithreading
Q.21 Medium Multithreading
What will happen if you try to call start() on a thread that has already completed execution?
A The thread will start again
B IllegalThreadStateException will be thrown
C The program will hang
D No error, start() will be ignored
Correct Answer:  B. IllegalThreadStateException will be thrown
EXPLANATION

Once a thread completes (reaches TERMINATED state), calling start() again throws IllegalThreadStateException. A thread can only be started once.

Take Test
Q.22 Easy Multithreading
Which of the following thread states is NOT a valid Java thread state?
A RUNNABLE
B BLOCKED
C SUSPENDED
D TERMINATED
Correct Answer:  C. SUSPENDED
EXPLANATION

Java thread states are: NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, and TERMINATED. SUSPENDED is not a valid state in Java's threading model.

Take Test
Q.23 Easy Multithreading
What is the difference between start() and run() methods in threading?
A start() creates a new thread, run() executes in the same thread
B run() creates a new thread, start() executes in the same thread
C Both are identical
D start() is deprecated in Java 21
Correct Answer:  A. start() creates a new thread, run() executes in the same thread
EXPLANATION

start() creates a new thread and calls run() in that new thread, while directly calling run() executes it in the current thread without creating a new thread.

Take Test
Q.24 Easy Multithreading
Which method must be implemented to create a thread in Java?
A start()
B run()
C execute()
D begin()
Correct Answer:  B. run()
EXPLANATION

The run() method must be implemented when creating a thread either by extending Thread class or implementing Runnable interface. The start() method calls run() internally.

Take Test
Q.25 Easy Multithreading
What is the output of the following code?
Thread t = new Thread(() -> System.out.println(Thread.currentThread().getName()));
t.start();
A Thread-0
B main
C Compilation error
D Runtime exception
Correct Answer:  A. Thread-0
EXPLANATION

When a new Thread is created without a name parameter, it gets a default name 'Thread-n' where n is a counter. The thread will print 'Thread-0' as it is the first thread created.

Take Test
Advertisement
Q.26 Hard Multithreading
In a producer-consumer problem, what is the ideal synchronization mechanism?
A BlockingQueue with synchronized wait/notify pattern
B Random sleep delays
C No synchronization
D Thread.yield() in loops
Correct Answer:  A. BlockingQueue with synchronized wait/notify pattern
EXPLANATION

BlockingQueue (like LinkedBlockingQueue) is purpose-built for producer-consumer patterns, handling synchronization and blocking elegantly.

Take Test
Q.27 Hard Multithreading
What is the purpose of the strictfp modifier in the context of multithreading?
A Ensures consistent floating-point calculations across platforms
B Prevents race conditions
C Forces strict thread scheduling
D It has no relevance to multithreading
Correct Answer:  A. Ensures consistent floating-point calculations across platforms
EXPLANATION

strictfp ensures consistent floating-point results across different platforms/JVMs, though it's not directly a multithreading construct.

Take Test
Q.28 Hard Multithreading
In a high-concurrency scenario using Java 21, which approach is recommended for I/O-bound operations?
A Virtual Threads with structured concurrency
B Traditional platform threads with thread pools
C Callbacks without threading
D Busy-waiting loops
Correct Answer:  A. Virtual Threads with structured concurrency
EXPLANATION

Virtual Threads (Project Loom) are ideal for I/O-bound operations as they have minimal overhead and can number in millions, improving scalability significantly.

Take Test
Q.29 Medium Multithreading
What is the key difference between Callable and Runnable?
A Callable can return a value and throw checked exceptions; Runnable cannot
B Runnable is faster than Callable
C Callable is used for single-threaded programs
D They are functionally identical
Correct Answer:  A. Callable can return a value and throw checked exceptions; Runnable cannot
EXPLANATION

Callable<V> can return a value of type V and throw checked exceptions. Runnable has void run() method and cannot throw checked exceptions.

Take Test
Q.30 Easy Multithreading
Which of the following collections is thread-safe in Java?
A ConcurrentHashMap
B HashMap
C TreeMap
D LinkedHashMap
Correct Answer:  A. ConcurrentHashMap
EXPLANATION

ConcurrentHashMap is designed for concurrent access without requiring external synchronization. HashMap and others are not thread-safe.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips