Posts

Showing posts from 2019

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...

The famous FizzBuzz problem

Today I came across the Developer survey results 2019 from stackoverflow.com . One of the questions asked in the survey was whether you have ever been asked to solve the FizzBuzz problem in an interview. I recollected that four years back I had coded this in an online test for an interview. I could write the code for it correctly, but the time I took was more than I should have. I decided to give it a try again today, and I feel this time I completed it in lesser time than in my attempt at the interview, but it was again not too great an improvement. After my code ran successfully, I looked over the internet for solutions posted by other people, in order to gain insights from them. I found my solution took a somewhat different approach. I couldn't find any solution that took the same approach as mine ,so I thought it would be nice to post my version of the solution. For those who don't remember the FizzBuzz problem, here is it : Write a program that prints the numbers ...