finitequeue heavy synchronization

Quartz <[email protected]> Fri, 5 Sep 2003 07:29:06 -0700 (PDT)
Newsgroups gmane.comp.java.seda.user
Message-ID <[email protected]>
Hi,

Looking at the FiniteQueue code, I see a very disturbing piece of code that I can't justify.
Can someone flag something I don't get?

The caller has no protection on the sanity of the queue size, once received, because it is not
synchronized anymore. And given that queue size is an int, not a long, java garantees atomic
assigment. So this size method requires no synchronization in my opinion.

  /** 
   * Return the size of the queue.
   */
  public int size() {
    synchronized(blocker) {
      synchronized(qlist) {
	return queueSize;
      }
    }
  }

But then, I'm wondering what dangerous non protected operation could depend on that size() call
return value. If a caller wants to protect the data, I expect it to do something like:

    synchronized(blocker) {
      synchronized(qlist) {
	if(queue.size()>0)
              //do stuff with queue;
      }
    }

which I can see in general.

Note that removing this extra synchronization on the size() would accelerate profiler and
threadpool size controller.

Any reason why I shouldn't remove synchronization? What is the "blocker" critical zone semantic?

Thanks.


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf