Threading

Thread Main Topics
  • Sleep, join, yield methods
  • Inter thread communication - wait() and notify(),  Blocking queues
  • Thread safety - Synchronized, Lock, Custom Locks
  • Semaphores
  • Dead Lock and Prevention techniques
  • ExecutorService
  • java.util.concurrent Package
Advantages of Runnable over Thread:
  1. As we are not modifying Threads behavior. There is no need for extending the thread. Composition is the preferred way. 
  2. Single Inheritance problem
  3. Extending Thread makes your logic tightly coupled with the Thread. You cannot pass the logic to other threads say threads created with executor. You have to always execute with the same thread.

Methods:
Join() - Thread instance method. Wait for the thread that is called on to die.
yield()- Static Method. Will move the currently running thread to Runnable state. No guarantee that the thread changes its state immediately.


Comments

Post a Comment

Popular posts from this blog

SQL Analytical Functions - Partition by (to split resultset into groups)

Distributed database design using CAP theorem

Easy approach to work with files in Java - Java NIO(New input output)