Mastering Java Threads and Concurrency is essential for developing efficient, responsive, and scalable applications. These MCQs cover topics such as thread creation, lifecycle, synchronization, and thread pool management.
run()start()execute()begin()Runnable interfaceThread classCallable interfaceRunnable interface in Java?
run(), for thread executionThread classRunnable interfaceExecutorService interfacethread.wait()Thread.sleep()thread.pause()Thread.yield()sleep()wait()notify()yield()start() method?
join() method do in Java?
volatilestaticsynchronizedfinalnotify() and notifyAll() methodswait()notify()yield()start()volatile keyword in Java?
synchronized is true?
Runnable objectsnew ThreadPool(5)Executors.newFixedThreadPool(5)ThreadPool.create(5)ExecutorService.createFixedPool(5)shutdown() do in an ExecutorService?
execute()submit()run()invoke()task.getResult()Future.get() methodThread.get()ThreadPool.getResult()ThreadPoolExecutorsThreadManagerRunnablePoolawait()waitAll()awaitTermination()finishAll()invokeAll() in ExecutorService?
run()execute()submit()call()stop()shutdown() or shutdownNow()terminate()close()| Qno | Answer |
|---|---|
| 1 | b) start() |
| 2 | d) Both a and b |
| 3 | c) To provide a single method, run(), for thread execution |
| 4 | c) Implementing the ExecutorService interface |
| 5 | b) Thread.sleep() |
| 6 | b) wait() |
| 7 | c) New |
| 8 | b) Runnable |
| 9 | b) It allows one thread to wait until another thread completes |
| 10 | b) Blocked |
| 11 | c) To prevent thread interference and data inconsistency |
| 12 | c) synchronized |
| 13 | a) A block that only one thread can execute at a time |
| 14 | a) Two threads competing for the same resources without release |
| 15 | c) Ensuring threads acquire locks in the same order |
| 16 | a) wait() |
| 17 | b) To make variable updates visible to all threads |
| 18 | b) It ensures that only one thread can access a resource at a time |
| 19 | c) To manage a pool of worker threads |
| 20 | b) Executors.newFixedThreadPool(5) |
| 21 | d) Blocks new tasks but allows existing tasks to finish |
| 22 | b) submit() |
| 23 | b) Using the Future.get() method |
| 24 | b) Minimizes thread creation overhead |
| 25 | b) Executors |
| 26 | a) It reuses threads and creates new ones if necessary |
| 27 | c) awaitTermination() |
| 28 | a) To submit multiple Callable tasks |
| 29 | b) execute() |
| 30 | b) By using shutdown() or shutdownNow() |