From the course: Advanced Java: Threads and Concurrency

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

The need for non-blocking operations

The need for non-blocking operations - Java Tutorial

From the course: Advanced Java: Threads and Concurrency

The need for non-blocking operations

- [Instructor] In a multi-threaded application, synchronization enables controlled access to shared data or resources, preventing memory inconsistency issues and thread interference. Here, controlled access really means sequential access. This is just like customers going to the cashier in the supermarket one after the other. The customers who are like trades do not interfere with each other in accessing the shared resource, cashier, and the goods of different customers will not mix. When code that processes shared data is enclosed in a synchronized block or a method, that code can only be executed by a single thread at a time. This ends up blocking code in our applications as threads have to be blocked, waiting for another to finish executing synchronized code. This way of programming is known as synchronous programming, and it's good when you need to ensure that tasks run sequentially or one after the other, especially when shared data or resources are accessed. However, this…

Contents