Return-Path: Delivered-To: apmail-incubator-river-dev-archive@minotaur.apache.org Received: (qmail 56412 invoked from network); 8 Feb 2011 15:45:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Feb 2011 15:45:56 -0000 Received: (qmail 64251 invoked by uid 500); 8 Feb 2011 15:45:56 -0000 Delivered-To: apmail-incubator-river-dev-archive@incubator.apache.org Received: (qmail 64120 invoked by uid 500); 8 Feb 2011 15:45:54 -0000 Mailing-List: contact river-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: river-dev@incubator.apache.org Delivered-To: mailing list river-dev@incubator.apache.org Received: (qmail 64102 invoked by uid 99); 8 Feb 2011 15:45:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Feb 2011 15:45:53 +0000 X-ASF-Spam-Status: No, hits=0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,RFC_ABUSE_POST,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of SRS0=+BpZ4I=VF=wonderly.org=gregg@yourhostingaccount.com designates 65.254.253.124 as permitted sender) Received: from [65.254.253.124] (HELO mailout15.yourhostingaccount.com) (65.254.253.124) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Feb 2011 15:45:45 +0000 Received: from mailscan10.yourhostingaccount.com ([10.1.15.10] helo=mailscan10.yourhostingaccount.com) by mailout15.yourhostingaccount.com with esmtp (Exim) id 1Pmpkq-0004ll-Ib for river-dev@incubator.apache.org; Tue, 08 Feb 2011 10:45:24 -0500 Received: from impout03.yourhostingaccount.com ([10.1.55.3] helo=impout03.yourhostingaccount.com) by mailscan10.yourhostingaccount.com with esmtp (Exim) id 1Pmpkq-0001IR-J1; Tue, 08 Feb 2011 10:45:24 -0500 Received: from authsmtp06.yourhostingaccount.com ([10.1.18.6]) by impout03.yourhostingaccount.com with NO UCE id 5TlP1g00M07rVmq0000000; Tue, 08 Feb 2011 10:45:23 -0500 X-EN-OrigOutIP: 10.1.18.6 X-EN-IMPSID: 5TlP1g00M07rVmq0000000 Received: from ip70-189-103-32.ok.ok.cox.net ([70.189.103.32] helo=[192.168.1.108]) by authsmtp06.yourhostingaccount.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim) id 1Pmpkk-0008N1-7m; Tue, 08 Feb 2011 10:45:21 -0500 Message-ID: <4D51650C.1090909@wonderly.org> Date: Tue, 08 Feb 2011 09:45:16 -0600 From: Gregg Wonderly User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 MIME-Version: 1.0 To: river-dev@incubator.apache.org CC: Patricia Shanahan Subject: Re: Bad idiom References: <4D50BFE9.2040900@acm.org> <4D515A72.2020600@wonderly.org> <4D515FC1.50606@acm.org> In-Reply-To: <4D515FC1.50606@acm.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-EN-UserInfo: 5bac21c6012e8295aaee92c67842fba3:d1e94006e19829b2b3cf849ab9ff0f3c X-EN-AuthUser: greggwon Sender: Gregg Wonderly X-EN-OrigIP: 70.189.103.32 X-EN-OrigHost: ip70-189-103-32.ok.ok.cox.net On 2/8/2011 9:22 AM, Patricia Shanahan wrote: > For shared counters, there is no need for an explicit MyClassName.class > reference. All I did was make the get-and-increment a static synchronized method > in the same class in which the counter itself is a static field. A static synchronized method is equivalently doing synchronized( MyBaseClass.class ) around the method definition. Glad you got it straightened out. Thanks for your work on these things! Gregg > > Doing local counters per class is fine, as long as every use of a single counter > synchronizes on the same object. > > The best solution is to make these counters AtomicInteger or AtomicLong. That > builds the concurrency control into the counter itself, eliminating the > possibility of synchronization errors. I eagerly await the outcome of the "drop > 1.4" vote. > > Patricia > > > Gregg Wonderly wrote: >> I think that there is a case either way. Some designs may, in fact want >> subclasses to share separate counters. Using the explicit MyClassName.class >> reference will create the shared lock for the super class and all sub classes. >> >> More often than not, I've used this when I wanted the subclasses to stand alone. >> >> Gregg Wonderly >> >> On 2/7/2011 10:00 PM, Patricia Shanahan wrote: >>> I found a bad synchronization idiom in a couple of the QA test programs for >>> outrigger. I've done what I can to grep for it, but be alert in case it shows up >>> in code you are reading. >>> >>> A non-final class needs to assign a unique number to each object of the class, >>> or any of its direct or indirect subclasses: >>> >>> // Declared in the class >>> private static int nextID=0; >>> >>> // Inside a constructor, or a method called from the constructor >>> synchronized(getClass()){ >>> id = nextID++; >>> } >>> >>> The synchronization is ineffective, because getClass() can return different >>> Class objects in a non-final class' constructor. >>> >>> Patricia >>> >>> >>> >>> >> >> > >