Java Multithreading

  1. Introduction
  2. Defining a Thread in java by extending Thread class.(7 special case)
  3. Defining a Thread in java using Runnable Interface
  4. Defining a Thread in java using Callable
  5. Naming of Thread, Getting and setting name of thread
  6. Thread priorities
  7. The methods to prevent Thread execution(Yield/Join/Sleep/Interrupt)
  8. Interrupt a sleeping,waiting thread.
  9. Thread Synchronization (synchronized method)
  10. Synchronized block
  11. Inter thread communication (wait/notify/notifyAll)
  12. Deadlock
  13. Demon Threads
  14. Green Thread stop(), suspend() and resume()
  15. Thread life cycle in java
  16. Thread Group
  17. Lock Interface of java.util.concurrent package
  18. ReentrantLock Class
  19. Executor Framework
  20. Thread pools (Executor Framework)
  21. Callable and Future
  22. Thread local
  23. Fork and Join Framework

Future Topics

  1. When to write a threadsafe code using vector?
  2. Transient, Volatile and Atomic Variables
  3. Concurrent Collections in java
  4. Stack size in Thread
  5. Producer Consumer Problem and Race Condition

Interview Questions :

  • What are the benefits of using Multithreading?
  • What is Thread in Java?
  • What are the two ways of implementing thread in Java?
  • What’s the difference between thread and process?
  • What’s the difference between class lock and object lock?
  • How many ways we can set a Thread name ?
  • What’s the difference between User thread and Daemon thread?
  • How can we create daemon threads? Example
  • What are the wait() and sleep() methods?
  • What’s the difference between notify() and notifyAll()?
  • Why wait(), notify(), and notifyAll() methods are present in Object class?
  • What is Runnable and Callable Interface? Write the difference between them.
  • What is the start() and run() method of Thread class?
  • Explain thread pool?
  • What’s the purpose of the join() method?
  • What do you mean by garbage collection?
  • Explain the meaning of the deadlock and when it can occur?
  • Explain volatile variables in Java?
  • How do threads communicate with each other?
  • Can two threads execute two methods (static and non-static concurrently)?
  • What is the purpose of the finalize() method?
  • What is the synchronization process? Why use it?
  • What is synchronized method and synchronized block? Which one should be preferred?
  • What is thread starvation?
  • What is Livelock? What happens when it occurs?
  • What is BlockingQueue?
  • Can you start a thread twice?
  • Explain context switching.
  • What is CyclicBarrier and CountDownLatch?
  • What do you mean by inter-thread communication?
  • What is Thread Scheduler and Time Slicing?
  • What is a shutdown hook?
  • What is busy spinning?
  • What is ConcurrentHashMap and Hashtable? In java, why is ConcurrentHashMap considered faster than Hashtable?
  • Explain thread priority.
  • What do you mean by the ThreadLocal variable in Java?
  • What is semaphore?
  • Explain Thread Group. Why should we not use it?
  • What is the ExecutorService interface?
  • What will happen if we don’t override the thread class run() method?
  • What is the lock interface? Why is it better to use a lock interface rather than a synchronized block.?
  • Is it possible to call the run() method directly to start a new thread?
  • Is it possible that each thread can have its stack in multithreaded programming?

Reference :