Multithreading Basics
1. What is multithreading in Java?
2. How does multithreading differ from multitasking?
3. Explain the concept of a thread and its role in a Java program.
4. What is the main advantage of using multithreading in Java?
Creating Threads:
1. How can you create a thread in Java?
2. Explain the difference between extending the Thread class and implementing the Runnable interface to create threads.
3. What are the benefits of using the Runnable interface over extending the Thread class?
Thread Lifecycle:
1. What are the various states in the lifecycle of a thread?
2. Explain the transition between states in a thread’s lifecycle.
3. How can a thread go from the Runnable state to the Blocked state?
4. What is the role of the wait() and notify() methods in thread synchronization?
Thread Priorities:
1. What are thread priorities in Java?
2. How are thread priorities used to influence thread scheduling?
3. How does the thread scheduler determine which thread to run next based on priorities?
4. Is thread priority the only factor that affects thread scheduling?
Thread Synchronization:
1. Why is thread synchronization important in multi threaded applications?
2. Explain the concepts of race conditions and thread interference.
3. How can you use the synchronized keyword to achieve thread synchronization?
4. What is the purpose of the wait(), notify(), and notifyAll() methods in synchronization?
Thread Safety:
1. What does it mean for a class or method to be thread-safe?
2. How can you achieve thread safety using synchronization blocks or methods?
3. Can you provide an example of a thread-safe class and explain how it ensures safety?
Deadlocks:
1. What is a deadlock and how does it occur in multi threading?
2. Explain the four conditions necessary for a deadlock to occur.
3. How can you prevent or resolve deadlocks in Java?
Thread Pooling:
1. What is a thread pool and why is it used?
2. Explain the advantages of using a thread pool over creating new threads for each task.
3. How do you create a thread pool using the Executor framework?
Java Concurrency API:
1. What is the Java Concurrency API?
2. How does the Executor framework simplify thread management?
3. Explain the difference between Executor Service and Executor.
Locks and Semaphores:
1. What are locks and how are they used for synchronization?
2. Explain the concept of a semaphore and its role in controlling access to shared resources.
Atomic Operations:
1. What are atomic operations and why are they important in multi threaded environments?
2. How do classes like AtomicInteger and AtomicReference help in achieving atomicity?
Thread Local Variables:
1. What are thread local variables and how are they used to store thread-specific data?
2. Provide an example of using ThreadLocal to store per-thread values.
Volatile Keyword:
1. What does the volatile keyword do in Java?
2. How can you use the volatile keyword to ensure visibility and prevent caching of variables?
Concurrency Challenges:
1. What challenges can arise in multi threaded programming besides synchronization and race conditions?
2. How can you avoid or handle issues like memory visibility and cache coherence?