ThreadLocal in Java

What is Thread Local? Values stored in these variables are local to threads, which mean that each thread puts and gets its own variable value. Lets see one example: Output: Thread-0 stored [Thread-0] in local and [Thread-0] in class variable Thread-1 stored [Thread-1] in local and [Thread-1] in class variable Read more…

Lock Interface In Java

What is Lock Interface? Lock provides the same functionality as a synchronized block. Like synchronized, a lock is a tool for controlling access to a critical region by multiple threads. Example using synchronized block: Example using Lock class: Note: how lock() and unlock() methods are called on Lock object to Read more…