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 Queue. Show all posts
Showing posts with label Queue. Show all posts

what is Queue?

10:45 PM
Queue 1. A queue can be defined as an ordered list which enables insert operations to be performed at one end called  REAR  and delete operations to be performed at another end called  FRONT . 2. Queue is referred to be as First In First Out list. 3. For example, people waiting in line for a rail ticket form a queue.   Applications of Queue Due to the fact that queue performs actions on first in first out basis which is quite fair for the ordering of actions. There are various applications of queues discussed as below. Queues are widely used as waiting lists for a single shared resource like printer, disk, CPU. Queues are used in asynchronous transfer of data (where data is not being transferred at the same rate between two processes) for eg. pipes, file IO, sockets. Queues are used as buffers in most of the applications like MP3 media player, CD player, etc. Queue are used to maintain the play list in media players in order to add and remove the so...

Producer Consumer problem Solution using BlockingQueue in Java Thread

1:14 AM
Producer Consumer Solution using BlockingQueue in Java Thread Producer Consumer problem is one of the classic multi-threading problems in computer science and the multi-threading world. It's tricky because it involves inter-thread communication, but it's important because most of the multi-threading problems fits into this category. There are many ways to solve producer consumer problem in Java e.g. you can solve this by using wait() and notify() method, as discussed here, or you can use the Semaphore to solve this problem. In this article, you will learn a third way to solve the producer-consumer problem by using the BlockingQueue in Java. It is arguably the simplest way to solve this problem in any programming language because blocking queue data structure not only provides storage but also provides flow control and thread-safety, which makes the code really simple. Brian Goetz has also explained this key class and pattern in his classic Java Concurrency in Practice book,...

.