Solving the Producer Consumer Problem in java using wait-notify
The Producer Consumer problem is one of the basic questions asked in an interview testing on Multi-threading concepts. A producer is a process that generates data and adds it to a fixed size shared object which may be a list, a queue, a stack -whatever you may choose. A consumer is a process that will simultaneously consume the data from that shared object. Things get complicated when a consumer starts consuming at a speed greater than that at which the data is being produced. It will then have to deal with an empty shared object. In such type of cases , a consumer has to wait , the producer will notify the consumer when it has added data and the consumer can pick up from then on. There may also be a case when the producer produces at a speed greater than that the consumer can consume , so the shared object is full of data. In that case, the producer has to wait. When the consumer has consumed some data to create space in the shared object, it can notify the producer, which ca...