Saturday, May 2, 2020

The Famous Producer & Consumer Problem in Java

Problem Statement:

There are two processes, a producer & a consumer, that share a common buffer with a limited size.
The producer produces data and stores it in buffer while the consumer consumes that data from by removing it from the buffer.
Having two processes running in parallel we need to make sure that producer will not put new data when the buffer size is full and consumer will not remove data from the buffer if the buffer size is empty.

Problem with Java classic approach:
The output turns out in exception:
The classic solution to the above problem: The output:

No comments:

Post a Comment

Terraform Cheat Sheet [WIP]

Installing Terraform