Re: driver initialization and connection separation

Поиск
Список
Период
Сортировка
Искать
От
Oliver Jowett
Тема
Re: driver initialization and connection separation
Дата
Msg-id
4B64E61B.3010302@opencloud.com
Ответ на
Список
Дерево обсуждения
Re: driver initialization and connection separation Oliver Jowett <oliver@opencloud.com>
Re: driver initialization and connection separation Richard Troy <rtroy@ScienceTools.com>
Re: driver initialization and connection separation Oliver Jowett <oliver@opencloud.com>
Re: driver initialization and connection separation Richard Troy <rtroy@ScienceTools.com>
Re: driver initialization and connection separation Richard Troy <rtroy@ScienceTools.com>
Re: driver initialization and connection separation Lew <noone@lwsc.ehost-services.com>
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
В списке pgsql-jdbc по дате отправления
От: Richard Troy
Дата:
От: Richard Troy
Дата:
FAQ