Java Assertions Quiz – 20 Questions with Answers
20 questions · 15 min · Medium
Test your knowledge of threads in Java, including thread creation, the Thread class, Runnable interface, thread lifecycle, synchronization, inter-thread communication, thread priorities, and concurrency.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
B. A lightweight unit of execution within a process
A thread is an independent path of execution within a process. Multiple threads can execute concurrently while sharing the process's resources.
A. Thread
The java.lang.Thread class provides methods for creating, starting, and managing threads.
C. Runnable
The Runnable interface defines a run() method that contains the task to be executed by a thread.
D. start()
Calling start() schedules a new thread of execution, which subsequently invokes its run() method. Calling run() directly does not start a new thread.
B. The method executes in the current thread
Calling run() directly is an ordinary method call. A new thread is started by calling start().
A. sleep()
Thread.sleep() pauses the currently executing thread for a specified duration, subject to scheduling and possible interruption.
C. synchronized
The synchronized keyword uses an object's monitor or a class monitor to coordinate access to protected code and establish memory visibility guarantees.
D. A situation in which the result depends on the timing or interleaving of concurrent operations
A race condition can occur when concurrent operations access shared state without sufficient coordination, causing results to depend on their execution order.
B. join()
Calling join() on a thread causes the current thread to wait until the target thread terminates, unless the wait is interrupted or a timed join expires.
A. interrupt()
The interrupt() method sets a thread's interrupt status and can cause certain blocking methods to throw InterruptedException. It does not forcibly terminate the thread.
C. Thread priority is a scheduling hint and does not guarantee execution order
Java thread priorities can influence scheduling, but the JVM and operating system do not guarantee that a higher-priority thread will execute first.
D. To wait for notification while releasing the monitor associated with the object
Object.wait() requires the current thread to own the object's monitor. It releases that monitor while waiting and reacquires it before returning or throwing InterruptedException.
A. notify()
Object.notify() wakes one thread waiting on that object's monitor, if any. The notifying thread must own the same monitor.
B. execute()
Executor.execute(Runnable) submits a task for execution without returning a Future. ExecutorService.submit() can return a Future representing the task.
C. The thread is waiting to acquire a monitor lock
A thread in the BLOCKED state is waiting to acquire an intrinsic monitor lock to enter a synchronized block or method.