What will be the output of the following code?
Object lock = new Object();
synchronized(lock) {
synchronized(lock) {
System.out.println("Nested");
}
}
Q.22Medium
Which interface would you use to submit multiple tasks and wait for all of them to complete?
Q.23Medium
What is the difference between notify() and notifyAll() in Java?
Q.24Medium
Which of the following best describes CyclicBarrier?
Q.25Medium
What happens when a thread acquires a lock on an object and then calls wait()?
Advertisement
Q.26Medium
In a scenario where Thread A holds Lock1 and waits for Lock2, while Thread B holds Lock2 and waits for Lock1, what is this called?
Q.27Medium
What is the output of this code?
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(() -> System.out.println("Task 1"));
executor.submit(() -> System.out.println("Task 2"));
executor.shutdown();
Q.28Medium
Which method is used to forcefully stop a thread in modern Java?
Q.29Medium
What happens if an exception is thrown inside a synchronized block?
Q.30Medium
In Java 21 Virtual Threads, what is the key advantage over platform threads?
Q.31Medium
What does the volatile keyword guarantee in Java multithreading?
Q.32Medium
What is the output of the following code?
volatile int counter = 0;
counter++; // in multiple threads
Which issue may occur?
Q.33Medium
What is CyclicBarrier used for in multithreading?
Q.34Medium
Which of the following is true about CountDownLatch?
Q.35Medium
What is the purpose of the wait() method in Java?
Q.36Medium
In a synchronized block, if notifyAll() is called, what happens?
Q.37Medium
What is the primary difference between Semaphore and Mutex?
Q.38Medium
What happens when Thread.interrupt() is called on a thread?
Q.39Medium
In a deadlock scenario, which of the following is always true?
Q.40Medium
What is the key difference between Callable and Runnable?