You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by 吴熊敏 <xw...@ublearning.com> on 2007/06/19 07:58:03 UTC

Re[2]: Share one singleton across webapps

You don't need to copy the jar-file to your webapps/lib in Eclipse.

Instead,you can add a external jar-file(which has been copied to
tomcat/lib) for the project in Eclipse.



On Mon, 18 Jun 2007 15:58:55 +0200
"Kevin Wilhelm" <Ke...@gmx.net> wrote:

> It works! Thanks!
> 
> The problem has been that each webapp had its own shared-lib jar-file, because I am developing in Eclipse. So Eclipse needs to know which classes I am accessing :/ At the end there were 3 times the same jar-file: 1st webapp, 2nd webapp, tomcat/lib.
> 
> Removing the jars from the webapps and leaving the one in tomcat/lib solved the problem.
> 
> However this is very disgusting. Every time I am deploying the 2 webapps to Tomcat, the jars are copied as well. I have to delete them manually, so that only the jar in Tomcat/lib is used. Is there some workaround for this? Should I use Ant for deploying then? But I won't be able to debug the webapps from within my IDE anymore since I am avoiding Eclipse's deployment mechanisms.
> 
> 
> -------- Original-Nachricht --------
> Datum: Mon, 18 Jun 2007 15:40:36 +0200
> Von: "Johnny Kewl" <jo...@kewlstuff.co.za>
> An: "Tomcat Users List" <us...@tomcat.apache.org>
> Betreff: Re: Share one singleton across webapps
> 
> > 
> > The typical form is like this
> > 
> > public class SingletonObject
> > {
> >     private SingletonObject(){}
> > 
> >     public static SingletonObject getSingletonObject()
> >     {
> >       if (ref == null)
> >           // it's ok, we can call this constructor
> >           ref = new SingletonObject();
> >       return ref;
> >     }
> > 
> >     private static SingletonObject ref;
> > }
> > 
> > If thats in Tomcat/lib.... it should share
> > Notice the use of static.... ie there is only one, no matter how many
> > times 
> > its started.
> > ...and the check for null.... which is how it determines it needs to make 
> > one instance if there is non...
> > 
> > Thats the trick.... a normal class which is what I imagine you trying,
> > will 
> > load once..... but instance many times.
> > 
> > Hope that helps... try not use them unless you really have to.
> > 
> > 
> > 
> > 
> > ----- Original Message ----- 
> > From: "Kevin Wilhelm" <Ke...@gmx.net>
> > To: <us...@tomcat.apache.org>
> > Sent: Monday, June 18, 2007 3:12 PM
> > Subject: Share one singleton across webapps
> > 
> > 
> > >I managed to get a jar file shared across two webapps in my Tomcat 6.
> > > Inside there is a class that represents a Singleton.
> > >
> > > The problem: the singleton class is instantiated by the first webapp and
> > > then again instantiated in the second webapp. So there are 2
> > > representations of the class and it is not really shared.
> > >
> > > There has to be a way to let the first webapp instantiate the singleton
> > > and set some property so that the second webapp can use the singleton
> > > and read the property. How do I achieve this?
> > > -- 
> > > Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
> > > Browser-Versionen downloaden: http://www.gmx.net/de/go/browser
> > >
> > > ---------------------------------------------------------------------
> > > To start a new topic, e-mail: users@tomcat.apache.org
> > > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > > For additional commands, e-mail: users-help@tomcat.apache.org
> > >
> > > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To start a new topic, e-mail: users@tomcat.apache.org
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> 
> -- 
> GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
> Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org

----------------------------
吴熊敏 <xw...@ublearning.com>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org