Return-Path: Delivered-To: apmail-harmony-dev-archive@www.apache.org Received: (qmail 42272 invoked from network); 15 Oct 2009 02:40:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 15 Oct 2009 02:40:59 -0000 Received: (qmail 91552 invoked by uid 500); 15 Oct 2009 02:40:59 -0000 Delivered-To: apmail-harmony-dev-archive@harmony.apache.org Received: (qmail 91461 invoked by uid 500); 15 Oct 2009 02:40:58 -0000 Mailing-List: contact dev-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list dev@harmony.apache.org Received: (qmail 91450 invoked by uid 99); 15 Oct 2009 02:40:58 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Oct 2009 02:40:58 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00 X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of nbeyer@gmail.com designates 209.85.216.180 as permitted sender) Received: from [209.85.216.180] (HELO mail-px0-f180.google.com) (209.85.216.180) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Oct 2009 02:40:56 +0000 Received: by pxi10 with SMTP id 10so188124pxi.4 for ; Wed, 14 Oct 2009 19:40:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=BpL58PB0q+renR5fvEI9VNXGtp2J8rL7D+i37insA+k=; b=Sw4Mw89TjQLjeV7oBNFYjzyDhM2SfCg5WUBg79sf3R9ULkfPcbXvxorPYFTs3S1qkj 4X/ZGRsUhMnGSByzyIuH/czgnyITVa5WjXPUytDgGG9EAibO5xS47lSFjxy3oWX7Tg32 b8Nku3vXRAsB5wkaLE3lerVH1wMQkWv8XdM5Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=rbe5gvrxYs9/mdVIPlB/267LNMixX5qZwIQIxX/7njv1Ti3JDBGViOFZfnmuXBC3t0 7YlvPK5aeuXEhu84rNd8QhNT5VqvSiyLJ8vGaG5NnWzbgAUL/Ln/um8CRo3AcuWtua3P Iz4s/mkS11LgWX4Az0Wf7HglfW4Mku09yadDc= MIME-Version: 1.0 Received: by 10.115.151.5 with SMTP id d5mr1582688wao.204.1255574057411; Wed, 14 Oct 2009 19:34:17 -0700 (PDT) In-Reply-To: <4AD59715.2000500@gmail.com> References: <20091011031344.389E823888DA@eris.apache.org> <4AD31751.3000704@gmail.com> <3b3f27c60910121918l2cdcec80kefea53c3350795f@mail.gmail.com> <4AD59715.2000500@gmail.com> Date: Wed, 14 Oct 2009 21:34:17 -0500 Message-ID: <3b3f27c60910141934i26ea5a07u9a9279d54cfaf571@mail.gmail.com> Subject: Re: svn commit: r824006 - in /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net: DatagramPacket.java DatagramSocket.java From: Nathan Beyer To: dev@harmony.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, Oct 14, 2009 at 4:17 AM, Tim Ellison wrote: > On 13/Oct/2009 19:59, Jesse Wilson wrote: >> On Mon, Oct 12, 2009 at 7:18 PM, Nathan Beyer wrote: >> >>> Honestly, the synchronization probably isn't appropriate on any of the >>> accessor/mutators - the granularity isn't correct. The locking >>> probably needs to encompass the entire method on DatagramSocket while >>> working on a particular DatagramPacket. Realistically, you don't want >>> the packet to change while processing. >>> >> >> A test shows that the RI uses synchronized. The following program doesn'= t >> complete: >> >> =C2=A0 public static void main(String[] args) throws Exception { >> =C2=A0 =C2=A0 byte[] data =3D new byte[] { 1, 2, 3, 4, 5 }; >> =C2=A0 =C2=A0 final DatagramPacket datagramPacket =3D new DatagramPacket= (data, >> data.length); >> >> =C2=A0 =C2=A0 ExecutorService executorService =3D Executors.newFixedThre= adPool(1); >> >> =C2=A0 =C2=A0 synchronized (datagramPacket) { >> =C2=A0 =C2=A0 =C2=A0 Future future =3D executorService.submit(ne= w Callable() >> { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 public byte[] call() throws Exception { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return datagramPacket.getData(); >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 } >> =C2=A0 =C2=A0 =C2=A0 }); >> >> =C2=A0 =C2=A0 =C2=A0 byte[] fromAnotherThread =3D future.get(); >> =C2=A0 =C2=A0 =C2=A0 System.out.println(Arrays.toString(fromAnotherThrea= d)); >> =C2=A0 =C2=A0 } >> =C2=A0 } >> >> >> Unfortunately, the concurrency support is shallow and not useful. Despit= e >> the fact that the RI has synchronized statements, it fails to defensivel= y >> copy the data array: >> >> =C2=A0 public static void main(String[] args) throws Exception { >> =C2=A0 =C2=A0 byte[] data =3D new byte[] { 1, 2, 3, 4, 5 }; >> =C2=A0 =C2=A0 final DatagramPacket datagramPacket =3D new DatagramPacket= (data, >> data.length); >> =C2=A0 =C2=A0 System.out.println("arrays are defensively copied? " + (da= ta !=3D >> datagramPacket.getData())); >> =C2=A0 } >> >> >> As a consequence, one thread could mutate the data array while another >> thread is consuming it. >> >> Regardless, it looks like synchronized and no defensive copying is the k= ey >> to compatibility with the RI. > > Thanks Jesse, > > I can't imagine that any application would rely on the methods being > synchronized (as opposed to the fields being consistent), but I agree > that we should leave it alone for compatibility sake. > > Unfortunately there are quite a few places where the RI implementation > leaves a bit to be desired -- which always makes it tempting to build a > better Java :-) In some circles, synchronized is just an implementation detail and not a definition of the interface. I think that may be on the SCJP test. We could consider that unless the synchronization characteristics are defined by the documentation, then don't have to abide by the same implementation details. -Nathan > > Regards, > Tim >