Hi have written a simple producer consumer problem using LinkedblockingQueue. My producer writes 1 to 10 in the queue and consumer reads from the queue using while loop inside run method as Below
while(true){
try {
System.out.println("Consumed: "+ sharedQueue.take());
} catch (InterruptedException ex) {
}
As per definition of blocking queue, blocking queue is blocked if there are no messages in the queue and it waits until message is put in queue. Because I am use a while loop ,will my consumer be blocked indefinitely?
Aucun commentaire:
Enregistrer un commentaire