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:
- As we are not modifying Threads behavior. There is no need for extending the thread. Composition is the preferred way.
- Single Inheritance problem
- 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.
Nice explanation on Advantages of Runnable...
ReplyDelete