tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felipe Schnack <feli...@ritterdosreis.br>
Subject Re: about singletons (ot)
Date Wed, 29 Jan 2003 20:47:34 GMT
  Strangely enough, a long time ago someone said me that static method
were slower to execute than normal ones... this makes no sense to me,
but anyone knows if this is true?
  Personally, I freak out when I see synch'd code where it can be
avoided :-))

On Wed, 2003-01-29 at 18:17, Tobias Dittrich wrote:
> 
> The reason why you don't want to use synchronized methods is that a
> synchronized block can only be executed by one thread at a time. Every other
> thread wanting to access this method will be blocked during this time (well,
> basically). So you want to try to keep the synchonized blocks as small as
> possible.
> 
> Having said that I wonder weather performance is an issue in the singleton
> vs only-static discussion. Is there a significant difference in execution
> speed? After all one has to make one additional method call every time when
> accessing a singleton method (the getInstance() which is  synchronized,
> too). And since we're off topic anyway: is a call to a static method faster
> than a "normal" one to an object (well, I mean the overhead from the method
> call, not the execution speed of the method body ... )?
> 
> 
> Cheers
> Tobi
> 
> 
> 
> From: "Erik Price" <eprice@ptc.com>
> To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
> Sent: Wednesday, January 29, 2003 1:46 PM
> Subject: Re: about singletons (ot)
> 
> 
> >
> >
> > Mike Jackson wrote:
> > > The difference is that if you use a singleton there's one instance.  If
> > > everything
> > > is static then you only have one copy.  Usually when you use a singleton
> > > it's to
> > > control access to some resource, the intent is that you use the
> singleton
> > > and some
> > > synchronized calls (note I don't mean synchronized methods, but
> synchronized
> > > code
> > > blocks) to control threads using that resource.
> >
> > Why could you not use synchronized methods?
> >
> >
> >
> > Erik
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
-- 

Felipe Schnack
Analista de Sistemas
felipes@ritterdosreis.br
Cel.: (51)91287530
Linux Counter #281893

Centro Universitário Ritter dos Reis
http://www.ritterdosreis.br
ritter@ritterdosreis.br
Fone/Fax.: (51)32303341


---------------------------------------------------------------------
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