Solved

Blocking Queue as Synchronizer

Posted on 2013-02-03
2
237 Views
Last Modified: 2013-02-18
hi

<<A Synchronizer is a object  that coordinates the control flow of threads based on its state,
Blocking queue can act as Synchornizer.>>--
 concurrency in practice- brian goetz page 94

Can anyone explain is simple terms with a simple example what this means?

Thanks
0
Comment
Question by:royjayd
2 Comments
 
LVL 16

Accepted Solution

by:
krakatoa earned 213 total points
ID: 38850581
Read this.
(If you want to).
0
 
LVL 16

Assisted Solution

by:Valeri
Valeri earned 212 total points
ID: 38850772
"A blocking queue is a queue that blocks when you try to dequeue from it and the queue is empty, or if you try to enqueue items to it and the queue is already full."
Because of that "queue" and "dequeue" operations need to be synchronized, because many threads are trying to "queue" and "dequeue" in one and the same time.
That's way "queue" and "dequeue" methods are synchronized, so it means that "this" (which is the BlockingQueue) is used as synchornizer. So in this case the blocking queue work's as synchornizer to it's self.
Btw in java 1.5 implementations of BlockingQueue (for example ArrayBlockingQueue) don't use the object itself for the synchronization. But the meaning in the book is that "queue" and "dequeue" methods could be synchronised by the BlockingQueue.

public synchronized void enqueue(Object item) {
}

public synchronized Object dequeue() {
}

both of this methods are synchronised on "this" object, which is the instance of the BlockingQueue.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now