You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by bogdan_cm <bo...@rbccm.com> on 2011/03/18 19:14:47 UTC

perthread or singleton

Hi, 
  I have a Tap5 service called QueryFactory. This service will include
dozens of methods for database interaction: selects, inserts, updates etc. 
This being an Web App, potentially multiple users ( threads ) will have the
service injected at the same time and "potentially" invoke the same method. 

Which path should I take: 
   - make the service perthread? -> not really a fan as the class could
become big and multiple instances can eat up memory. 
   - go with singleton and synchronize all the methods inside it?

As the methods return void and do not change any shared variable, they are
basically atomic operations even without the use of the synchronized
keyword. 

Any suggestions?

Thanks, 
Bogdan. 


   
   
   

--
View this message in context: http://tapestry.1045711.n5.nabble.com/perthread-or-singleton-tp3975921p3975921.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: perthread or singleton

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 18 Mar 2011 15:14:47 -0300, bogdan_cm <bo...@rbccm.com>  
wrote:

> Hi,

Hi!

> As the methods return void and do not change any shared variable, they  
> are
> basically atomic operations even without the use of the synchronized
> keyword.
>
> Any suggestions?
>
> Thanks,
> Bogdan.
>
>
>
> --
> View this message in context:  
> http://tapestry.1045711.n5.nabble.com/perthread-or-singleton-tp3975921p3975921.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
Consultor, desenvolvedor e instrutor em Java, Tapestry e Hibernate
Coordenador e professor da Especialização em Engenharia de Software com  
Ênfase em Java da Faculdade Pitágoras
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: perthread or singleton

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 18 Mar 2011 15:14:47 -0300, bogdan_cm <bo...@rbccm.com>  
wrote:

> Hi,

Hi!

> As the methods return void

This doesn't make any difference as long as the returned value isn't  
shared between threads or it doesn't have mutable state.

> and do not change any shared variable, they are
> basically atomic operations even without the use of the synchronized
> keyword.

If what you wrote is correct about your code, your service can be  
singleton-scoped.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org