From: Heikki Linnakangas <hlinnakangas@vmware.com>
To: Heiko W. Rupp <hwr@pilhuhn.de>
Cc: Vitalii Tymchyshyn <vit@tym.im>
Cc: PG-JDBC Mailing List <pgsql-jdbc@postgresql.org>
Subject: Re: Remove usage of finalizers ?
Date: Mon, 21 Oct 2013 18:17:36 +0300
Message-ID: <52654590.1050600@vmware.com> (raw)
In-Reply-To: <B86EB807-F8DF-4F2A-BBC9-6CAB925FCDE9@pilhuhn.de>
References: <9E5438C0-0A2E-4543-BE06-1E7A6D0E3B83@pilhuhn.de>
<CABWW-d2rT-dGEh-hrtemgo2z6dm5H2VUz86y-xmgs3p_6Hv+_w@mail.gmail.com>
<E177372F-3F90-4F1D-9A34-84B3A678A988@pilhuhn.de>
<CABWW-d2EfWuCV7ZDGoWpz1GiFEM_zNX6rq1PHdHNm_HbZ3EM2w@mail.gmail.com>
<B86EB807-F8DF-4F2A-BBC9-6CAB925FCDE9@pilhuhn.de>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
On 21.10.2013 13:09, Heiko W. Rupp wrote:
> Am 21.10.2013 um 11:34 schrieb Vitalii Tymchyshyn:
>> Note that removing finalizers without introducing some other mechanism, like reference queues, would introduce server side leaks on poorly written yet correct applications!
>
> Server side leaks are introduced the moment that you rely on a finalizer being called (close to the time the object is no longer needed).
> Per JLS, the finalizers are a) not guaranteed to ever run, b) run in any specific order c) at any given time.
>
> And the other mechanisms exist -- close() calls. Software that relies on the finalizer for this cleanup may show unpredictable
> behavior.
If we can't get rid of the finalizer completely, I wonder if we could
arrange things so that we could avoid the finalizer overhead when there
are server-side resources associated with the statement. I would guess
that in most cases that you don't close a Statement properly, it's a
very short-lived Statement used to run a single query. Such a statement
will typically not have any server-side resources associated with it.
Actually, we already seem to use PhantomReferences to clean up orphaned
SimpleQuery and Portal objects. AFAICS those are the things that
actually represent server-side resources. Why do we even have a
finalizer in AbstractJdbc2Statement? Perhaps we used to rely on the
finalizer to clean up things, but later added the more fine-grained
PhantomReferences to the underlying objects, making the finalizer redundant?
> Another reason to get rid of finalize() methods is that Object creation is several hundred times slower with the finalize()
> methods present, as not only the Statement etc. is created, but also the Finalizer and the later needs to be put on the finalizer
> queue. Josh Bloch talks about 5.6ns vs 2400ns for a simple object in "Effective Java, 2nd edition".
> That is a penalty everyone has to pay - even if they close Statements etc correctly.
That's still negligible compared to sending a statement to the remote
host and getting the result back, though.
- 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, hwr@pilhuhn.de, vit@tym.im
Subject: Re: Remove usage of finalizers ?
In-Reply-To: <52654590.1050600@vmware.com>
References: <9E5438C0-0A2E-4543-BE06-1E7A6D0E3B83@pilhuhn.de> <CABWW-d2rT-dGEh-hrtemgo2z6dm5H2VUz86y-xmgs3p_6Hv+_w@mail.gmail.com> <E177372F-3F90-4F1D-9A34-84B3A678A988@pilhuhn.de> <CABWW-d2EfWuCV7ZDGoWpz1GiFEM_zNX6rq1PHdHNm_HbZ3EM2w@mail.gmail.com> <B86EB807-F8DF-4F2A-BBC9-6CAB925FCDE9@pilhuhn.de> <52654590.1050600@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