Java implementation of the Producer Consumer threading problem