Solved

Blocking Queue as Synchronizer

Posted on 2013-02-03
2
240 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping2 challenge 13 89
Spring Framework HTTPSession management 1 33
eclipse apache tomcat admin console 52 94
Detect Closed Loops (circles, figure-8s, etc) in PNG Images 6 31
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

813 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

10 Experts available now in Live!

Get 1:1 Help Now