JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

Showing posts with label BlockingQueue. Show all posts
Showing posts with label BlockingQueue. Show all posts

BlockingQueue in java

8:48 AM
BlockingQueue in java BlockingQueue  is introduced in java with concurrent package with  ConcurrentHashMap . It is thread safe queue to put and take elements from it. BlockingQueue  is special type of queue which is used when one thread produces object and another thread consumes it. Producer thread will keep inserting objects to queue until it reaches upper limit. Once this queue size has reached that limit then producer thread will get blocked and won’t able to put objects into queue until consumer thread starts consuming it. Similarly consumer thread keep taking objects from queue until queue becomes empty. Once queue becomes empty, consumer thread get blocked and waits for producer threads for inserting objects into the queue. If you put null to BlockingQueue, it will NullPointerException at run time. It has two important methods put :  producer thread put objects into the queue until it reaches to the limit and waits for consumer thr...

.