tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cox, Charlie" <c...@cincom.com>
Subject RE: [Q] Singleton Objects across webapps...
Date Thu, 05 Sep 2002 13:27:56 GMT
it depends on where you want your servlets to reside. If all your servlets
reside in the same context, you can leave your singleton in that context.
This way if you have multiple contexts with copies of the same servlets, you
can have an instance of your singleton for each webapp.

if you want to share between servlets within different contexts, you should
put them in /common/lib, as Yoav suggested. This way you will have only one
instance of your singleton, shared by any context that uses it.

you may also want to review the classloader doc.
Charlie

> -----Original Message-----
> From: Per Kreipke [mailto:per@onclave.com]
> Sent: Wednesday, September 04, 2002 3:44 PM
> To: Tomcat Users List
> Subject: RE: [Q] Singleton Objects across webapps...
> 
> 
> I hate to repost but I'm not clear why no one has any advice.
> 
> Am I asking such a simple question that I just missed it in the FAQ
> somewhere?
> 
> _any_ pointer is appreciated.
> 
> Per
> 
> > A "best practices" question:
> >
> > What is the best way of sharing a single, changeable copy of common
> > information across multiple servlets?
> >
> >
> > Example Scenario:
> >
> > Using two servlets (webdav and cocoon), I need to share 
> common information
> > between them.
> >
> > There are two choices for how to host the servlets, each of 
> which affects
> > the options for sharing info:
> >
> > - host the servlets in different contexts (a likely requirement
> > if security
> > constraints differ)
> >
> > - host the servlets in the same context.
> >
> >
> > Then, within each servlet you could share the information through:
> > - singleton classes
> >  + pro: conceptually simple
> >  + con: singleton pattern isn't bulletproof
> >  + con: threading issues?
> >  + con: lifecyle issues (can't use servlet destroy() if 
> have multiple
> > servlets)
> >
> > - avalon roles
> >  + pro: convenient, correct lifecycle management
> >  + pro: using avalon in other apps (James) in same JVM could also
> > share info
> >  + con: poolable (e.g. multiple instances) and not the same 
> as singleton
> >
> > - context attributes
> >  + pro: conceptually simple, no singleton coding necessary
> >  + con: HTTP specific, information can't be shared with non 
> TC app (James)
> >  + con: can't share across contexts, all servlets must live 
> in same webapp
> >
> > - enterprise javabeans
> >  + pro: managed
> >  + con: requires J2EE server?
> >
> > 1) Are there other options I'm missing?
> >
> > 2) What have people found to be the best pattern?
> >
> > 3) Besides the servlet 2.3 reference docs and O'Reilly 
> books, can anyone
> > recommend reading material that includes these issues (most 
> introductory
> > books cover the same 'your first webapp' type of material).
> >
> >
> > Thanks in advance for your opinion,
> > Per
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: 
> <mailto:tomcat-user-help@jakarta.apache.org>
> 

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


Mime
View raw message