Special thread features

Shutdown Hook : Shutdown Hooks are pre-registered (but yet-to-be-started) threads which are run by JVM when an application is shutting down. There can be more that one shutdown hooks registered with a JVM, JVM does not give any guarantee on the order i...

Points to consider while working on multithreaded code

In general, there are 4 main points to consider when it comes to dealing with multithreaded code : mutual exclusion caching reordering happens-before Let's examine each of them in detail : Mutual Exclusion : Mutual Exclusion essentially means that only...

Common concurrency problems

Starvation Starvation refers to a situation where a thread is unable to make any progress (or progressing very slowly) despite being in runnable state. Some of the common causes of starvation are : Other 'greedy' threads with higher priority are hogg...

Threads and Processes

What is a thread ? A thread is a kernel abstraction for scheduling work on the CPU. A thread is essentially an execution context which a CPU needs to execute a bunch of instructions. As a bare minimum coding construct, any thread implementation will ha...