Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Blocking Queue as Synchronizer

Posted on 2013-02-03
2
Medium Priority
?
250 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 852 total points
ID: 38850581
Read this.
(If you want to).
0
 
LVL 16

Assisted Solution

by:Valeri
Valeri earned 848 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

715 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