Solved

Blocking Queue as Synchronizer

Posted on 2013-02-03
2
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Selenium docs api java index 3 98
web project error add remove 1 85
jsp error 6 72
activeMQ Queue Messages Enqueued and Messages Dequeued 1 120
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

710 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