producer - consume; how does the consumer stop?
问题 So I have simulated my producer consumer problem and I have the code below. My question is this: how does the consumer stops if he's in constant while(true). In the code below, I've added if (queue.peek()==null) Thread.currentThread().interrupt(); which works nicely in this example. But in my real world design, this doesn't work (sometimes it takes longer time to the producer to 'put' the data so the exception thrown in the consumer is incorrect. In general, I know I can put a 'poison' data