Tuesday, 13 September 2016

Producer Consumer Problem using Multithreading in JAVA

One of my  friends had faced this problem during his interview in Subex. Concept is pretty simple here. We have two threads here. Consumer thread can not consume anything unless and until Producer Thread has produced.

There are couple of ways to solve this problem. Here I am using volatile Stack to solve this.

Implemented Code:







Sample Output:





No comments:

Post a Comment