Multithreading And Concurrency

1.Which interface must be implemented to create a thread in Java?
  • A. Comparable
  • B. Serializable
  • C. Runnable
  • D. Callable

Runnable

Runnable

2.Which method is used to start the execution of a thread?
  • A. run()
  • B. execute()
  • C. start()
  • D. init()

start()

start()

3.What is a ThreadLocal variable primarily used for?
  • A. To store a thread's priority.
  • B. To share data safely among all threads.
  • C. To provide each thread with its own independent copy of a variable.
  • D. To synchronize access to a shared resource.

To provide each thread with its own independent copy of a variable.

To provide each thread with its own independent copy of a variable.

4.Which keyword is used to achieve synchronization in Java?
  • A. volatile
  • B. transient
  • C. synchronized
  • D. static

synchronized

synchronized

5.What is the primary purpose of an ExecutorService?
  • A. To manage and reuse threads for executing tasks.
  • B. To provide a framework for distributed computing.
  • C. To enable communication between different JVMs.
  • D. To manage memory allocation for threads.

To manage and reuse threads for executing tasks.

To manage and reuse threads for executing tasks.