ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eugeny N Dzhurinsky <eugeny...@jdevelop.com>
Subject Re: best method to get SqlMapClient in web application
Date Tue, 25 Oct 2005 15:16:56 GMT
On Tue, Oct 25, 2005 at 10:00:31AM -0500, Jeff Butler wrote:
> I would say it's not *exactly* singleton, but close enough. And it certainly
> works. As to the question "why not this?", I have these thoughts:
>  <joking>It's not cool as cool as the other ways, and we're all about
> cool</joking>
>  On a more serious note, I do try to avoid Singletons and static
> methods/variables if possible. Sometimes it's not possible, but if there is
> a simple alternative I will take it. I think the best reason I can give for
> this philosophy is that I want to be in more explicit control over when
> initialization occurs. Static variables are initialized at first class
> reference, and it's not always easy to predict when that will be.
>  But, of course, this is more philosophy than science. Sometimes in our
> efforts to do something elegant, we make things too complex. There can be a
> trade off between simple and elegant - your milage may vary. If it works,
> and is maintainable, and you are happy with it, then I say "go for it".

Completely agree, initialization order of classes in general is ambigous, so
you may fall in mazy problems with simple reason at the background (some class
was depend of static section initialization of another class, but JVM thinks
in different way).

Regarding iBATIS SqlClientMap instance - in web application I'm keeping it
inside some static variable of some servlet, which is auto-loaded at container
startup, and then using static method to get an instance of this private
static member. That's it and it works fine :)

Eugene N Dzhurinsky

View raw message