pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: Richard Troy <rtroy@ScienceTools.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: driver initialization and connection separation
Date: Sun, 31 Jan 2010 15:08:27 +1300
Message-ID: <4B64E61B.3010302@opencloud.com> (raw)
In-Reply-To: <Pine.LNX.4.33.1001301701540.6187-100000@denzel.in>
References: <Pine.LNX.4.33.1001301701540.6187-100000@denzel.in>

Richard Troy wrote:

> It seems to me that there's something missing from the initialization
> code, namely to remove the SSL features if the driver was already loaded.
> It should only be loaded when a URL asking for it comes along with the
> option ssl=true (for example). However, one could easily argue that it's
> not the initialization code that needs help but the code that constructs a
> new connection; it makes just as much sense that the request for a new
> connection give the appropriate type of connection, with or without SSL
> depending on whether the option in the URL was specified.

Driver initialization has nothing to do with this; you are making 
assumptions about Class.forName() that are not correct. It does not 
"initialize" the driver in any way other than what the JVM requires for 
any other class (see below)

If you get a different sort of SSL-vs-not-SSL connection for the same 
connection URL depending on what connections you got in the past - that 
*is* a bug. Do you have a testcase showing the problem?

> ...Your follow-on comment (below) about classes being initialized only
> once isn't helpful here because it isn't clear to me whether this is a
> case of initializing an object or loading _code_ that instantiates
> objects. In other words, even though I've been using Java since it's first
> release, I've never before had to worry about the code that instantiates
> objects changing while my code is running, so I haven't thought about it
> much. To my mind, each instance of my objects which then instantiate other
> objects - like JDBC connection objects - should get clean, separate and
> distinct objects, so in effect the driver code is loaded multiple times.
> But as I said, I could be wrong - I don't know much about how the JVM
> manages code that's loaded, but my suspicion is that it'll manage the
> individual instances of loading the same driver separately.

Class.forName()'s comment about initialization is talking about class 
initialization as described in the JVM spec - it involves (for example) 
running static initializer blocks in the class. This is guaranteed to 
happen before certain uses of the class (e.g. calling any method), and 
can be forced early via Class.forName(). But it is only ever done once 
per class.

If you load the same class in a different classloader, it's effectively 
a different class, so will be separately initialized. (But I don't 
recommend doing that with the JDBC driver, because it'll mess with 
driver registration)

-O



view thread (7+ messages)  latest in thread

Message-ID: <4B64E61B.3010302@opencloud.com>
Permalink:  ../4B64E61B.3010302@opencloud.com/
Also on:    postgresql.org/message-id/4B64E61B.3010302@opencloud.com

 · 

reply

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: oliver@opencloud.com, rtroy@ScienceTools.com
  Subject: Re: driver initialization and connection separation
  In-Reply-To: <4B64E61B.3010302@opencloud.com>
  References: <Pine.LNX.4.33.1001301701540.6187-100000@denzel.in> <4B64E61B.3010302@opencloud.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