tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Will Hartung" <wi...@msoft.com>
Subject Re: singleton creation (ot)
Date Wed, 05 Feb 2003 18:58:15 GMT
> From: "Felipe Schnack" <felipes@ritterdosreis.br>
> Sent: Wednesday, February 05, 2003 4:05 AM
> Subject: RE: singleton creation (ot)


>  I'm not sure yet of how I will do it... I would not like to
> synchronize the entire method because it'll probably be called million
> of times in my app

Then don't call it a million times in your app. Call it once at startup and
stick it in a property in the Context. (Of course, calls to get properties
out of the context may be synchronized, I haven't looked.)

Or simply don't synchronize it and load the singleton at startup, when you
are in more control of the environment and have confidence that a race
condition isn't happening, or at least is not important.

The whole point of the synchronize is to serialize requests during race
conditions. Make the requests when this isn't happening and be done with it.

The generic Singleton pattern works fine when applied genericly to generic
code. In this case you have a higher knowledge of how its being used and can
make decisions based upon that knowledge.

Finally, as a self-rebuttal, "Don't worry about it at all unless it becomes
a problem. Early optimization is the source of many evils".

Regards,

Will Hartung
(willh@msoft.com)




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message