Producer Consumer Problem in JAVA using wait() and notify()
This is also known as bounded-buffer problem and classical example of multi-thread/multi-process synchronization problem. This problem sometime plays crucial role during java interview if you are not familiar with proper understanding. Scenario is, There is single buffer where Producer writes some data and waits for Consumer to read it. Consumer reads the data from buffer and waits for more data to be available. This situation continuous to go on same way further. Now Producer has to wait until Consumer finished before it writes more data. And same way, After read, Consumer has to wait until Producer produces more data. This wait is implemented using "Polling". Polling is usually implemented by loop that is used to check some condition repeatedly. Once condition is met appropriate action is taken. "Polling" waste CPU time. This Polling can be avoided by using wait(), notify() and notifyAll() method. These method are implemented as final method in Obje...