From: Heikki Linnakangas <hlinnakangas@vmware.com>
To: Florent Guillaume <fg@nuxeo.com>
Cc: Bryan Varner <bvarner@polarislabs.com>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: PostgreSQL XAResource & GlassFish 3.1.2.2
Date: Tue, 12 Feb 2013 20:48:48 +0200
Message-ID: <511A8E90.4010202@vmware.com> (raw)
In-Reply-To: <CAF-4BpMPm3v1sVh=G2W3frMDb3MTJcuqxx4Uc2ZLPKtpM4Ws9Q@mail.gmail.com>
References: <A2B35D2698B0C74F9B8333525E67ED0135F89007@plindyexch02.polarislabs.lan>
<511A2C7F.1040104@vmware.com>
<511A675B.3020207@polarislabs.com>
<511A8BAC.7080400@vmware.com>
<CAF-4BpMPm3v1sVh=G2W3frMDb3MTJcuqxx4Uc2ZLPKtpM4Ws9Q@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
On 12.02.2013 20:41, Florent Guillaume wrote:
> On Tue, Feb 12, 2013 at 7:36 PM, Heikki Linnakangas
> <hlinnakangas@vmware.com> wrote:
>> I see. I think there's yet another potential explanation: even if glassfish
>> is careful to invoke the end() only after start() has fully finished in the
>> other thread, the java memory model does not guarantee that the effects of
>> the end() in one thread are visible to the other thread doing the start().
>> The update of the PGXAConnection's state-variable might be sitting in the
>> CPU cache of the CPU running the first thread, not yet visible to the second
>> thread.
>
> That's the whole point of volatile since Java 5, it enforces a barrier
> and "happens-before" semantics.
>
>> However, I'm not sure if glassfish could guarantee that the start()
>> has really finished before end() is called, without using some operation
>> that would also force the CPU cache to be flushed, making the effects
>> visible.
>>
>> In any case, it seems like we should add "synchronized" to all the public
>> methods in PGXAConnection. The performance penalty should be minimal, and it
>> would fix any race conditions of that sort.
>
> For Java 5+ this is really overkill.
Well, volatile will only fix the issue if it's indeed "just" because of
weak memory ordering issues. However, if the cause is a genuine race
condition where glassfish calls end() in one thread before the start()
in another thread has ran to completion, as Bryan suspected, then
volatile is not enough. Besides, it would be good for PGXAConnection to
be thread-safe in general, like the rest of the JDBC driver.
- Heikki
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: hlinnakangas@vmware.com, fg@nuxeo.com, bvarner@polarislabs.com
Subject: Re: PostgreSQL XAResource & GlassFish 3.1.2.2
In-Reply-To: <511A8E90.4010202@vmware.com>
References: <A2B35D2698B0C74F9B8333525E67ED0135F89007@plindyexch02.polarislabs.lan> <511A2C7F.1040104@vmware.com> <511A675B.3020207@polarislabs.com> <511A8BAC.7080400@vmware.com> <CAF-4BpMPm3v1sVh=G2W3frMDb3MTJcuqxx4Uc2ZLPKtpM4Ws9Q@mail.gmail.com> <511A8E90.4010202@vmware.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox