You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kevin Wilhelm <Ke...@gmx.net> on 2007/06/18 15:12:48 UTC

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


Re[2]: Share one singleton across webapps

Posted by 吴熊敏 <xw...@ublearning.com>.
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


Re: Share one singleton across webapps

Posted by Kevin Wilhelm <ke...@gmx.net>.
Related to the usage of shared Singletons in Tomcat: In fact my shared 
Singleton class provides other webapps with one factory that produces 
service objects (those are instantiated every time a request is made). Those 
service objects will handle DTOs and will convert them to normal database 
entities before persisting. All of these entity operations are however 
transactionized, so do I really need Thread handling for this kind of stuff? 
In my opinion transations might be sufficient to ensure clean access.

The only point to consider is: do I have to synchronize anything anymore? 
Sure at the beginning I have to ensure the Singleton gets its factory 
injected. From then on every webapp should be able to access the factory's 
produce-methods without the need for synchronization?!


----- Original Message ----- 
From: "Johnny Kewl" <jo...@kewlstuff.co.za>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Monday, June 18, 2007 6:08 PM
Subject: Re: Share one singleton across webapps


> Kevin, I dont know Eclipse,
> But it sound very much the same as what Netbeans does.
> ie it will also give every web app its own library.
>
> Being able to share, is sometimes handy, its an alternative to context 
> sharing, and JNDI, for instance if you want to set up your own dB pool.... 
> BUT.... as a rule of thumb, what these IDE's are doing, is right. Each web 
> app should gets its own set of libraries.
>
> The thing to remember is that Tomcat is multi - threaded.
> When each web app has its own lib, you dont need to worry about that, well 
> not as much anyway.... BUT now you do....  you have shared single instance 
> library, and if 30 simultaneous servlets start up, and they all want that 
> library, weird stuff can happen.
> So now, the next thing you have to do is make sure its thread safe, and 
> then once you have done that, you may find when the servlets are busy, 
> they all slow down.
>
> Anyway, thats why I said, use them "unwillingly"... because if you not 
> carefull, you may be making the slowest Tomcat server ever ;)
>
>
> ----- Original Message ----- 
> From: "Kevin Wilhelm" <Ke...@gmx.net>
> To: "Tomcat Users List" <us...@tomcat.apache.org>
> Sent: Monday, June 18, 2007 3:58 PM
> Subject: Re: Share one singleton across webapps
>
>
>> 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
>>
>>
>
>
> ---------------------------------------------------------------------
> 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


Re: Share one singleton across webapps

Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
Kevin, I dont know Eclipse,
But it sound very much the same as what Netbeans does.
ie it will also give every web app its own library.

Being able to share, is sometimes handy, its an alternative to context 
sharing, and JNDI, for instance if you want to set up your own dB pool.... 
BUT.... as a rule of thumb, what these IDE's are doing, is right. Each web 
app should gets its own set of libraries.

The thing to remember is that Tomcat is multi - threaded.
When each web app has its own lib, you dont need to worry about that, well 
not as much anyway.... BUT now you do....  you have shared single instance 
library, and if 30 simultaneous servlets start up, and they all want that 
library, weird stuff can happen.
So now, the next thing you have to do is make sure its thread safe, and then 
once you have done that, you may find when the servlets are busy, they all 
slow down.

Anyway, thats why I said, use them "unwillingly"... because if you not 
carefull, you may be making the slowest Tomcat server ever ;)


----- Original Message ----- 
From: "Kevin Wilhelm" <Ke...@gmx.net>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Monday, June 18, 2007 3:58 PM
Subject: Re: Share one singleton across webapps


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


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


Re: Share one singleton across webapps

Posted by Kevin Wilhelm <Ke...@gmx.net>.
Hi,

thanks for your advice. I knew the plugin page before. This should be the first-choice when searching for Eclipse add ons.

Currently I am happy about having solved the problem. It's possible to include other JAVA-projects into the build path of an Eclipse-Web-Project. So far so good.

Taking this approach instead of including the shared jar file concludes in setting some interesting property for the web project to be deployed: "How should dependent Java projects be handled during deployment? -> Ignore dependent Java projects (I will manually manage them)" instead of " -> Jar dependent Java project output and place in 'lib' directory" which was standard.

So from now on the shared classes are contained within my development environment (Eclipse) and left out of the deployed version in Tomcat, which has its own unique version of the shared lib. Fantastic!

By the way, what means "UAT and QA jars"?


-------- Original-Nachricht --------
Datum: Mon, 18 Jun 2007 10:11:58 -0400
Von: "Martin Gainty" <mg...@hotmail.com>
An: "Tomcat Users List" <us...@tomcat.apache.org>
Betreff: Re: Share one singleton across webapps

> Good Morning Kevin
> 
> Glad to hear that worked for you
> 
> What I found is that Eclipse has it's own plugins for virtually every
> major 
> system/subsystem as illustrated here
> http://www.eclipseplugincentral.com/Web_Links+main.html
> 
> When exporting your build file to build.xml you will need to determine
> which 
> jars will work in dev (as Eclipse plugin) vs UAT and  QA jars
> 
> Please keep us apprised of your progress
> 
> M--
> This email message and any files transmitted with it contain confidential
> information intended only for the person(s) to whom this email message is
> addressed.  If you have received this email message in error, please
> notify
> the sender immediately by telephone or email and destroy the original
> message without making a copy.  Thank you.
> 
> ----- Original Message ----- 
> From: "Kevin Wilhelm" <Ke...@gmx.net>
> To: "Tomcat Users List" <us...@tomcat.apache.org>
> Sent: Monday, June 18, 2007 9:58 AM
> Subject: Re: Share one singleton across webapps
> 
> 
> > 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
> >
> > 
> 
> 
> ---------------------------------------------------------------------
> 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


Re: Share one singleton across webapps

Posted by Martin Gainty <mg...@hotmail.com>.
Good Morning Kevin

Glad to hear that worked for you

What I found is that Eclipse has it's own plugins for virtually every major 
system/subsystem as illustrated here
http://www.eclipseplugincentral.com/Web_Links+main.html

When exporting your build file to build.xml you will need to determine which 
jars will work in dev (as Eclipse plugin) vs UAT and  QA jars

Please keep us apprised of your progress

M--
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed.  If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy.  Thank you.

----- Original Message ----- 
From: "Kevin Wilhelm" <Ke...@gmx.net>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Monday, June 18, 2007 9:58 AM
Subject: Re: Share one singleton across webapps


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


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


Re: Share one singleton across webapps

Posted by Andre Prasetya <an...@gmail.com>.
I m assuming you're using WTP and Eclipse. To avoid that disgusting problem,
add the problematic jar to build path only and not to J2EE module
dependency.

UAT : User Acceptance Test
QA : Quality Assurance


On 6/18/07, 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
>
>


-- 
-Andre-

People see things the way they are and say "why ?" I see things that never
were and say "Why not ?"

RE: Share one singleton across webapps

Posted by "Nelson, Tracy M." <Tr...@nelnet.net>.
| From: Kevin Wilhelm [mailto:KevinWilhelm@gmx.net]
| Sent: Monday, 18 June, 2007 08:59
| 
| 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.

You should still be able to use Eclipse, just make sure Tomcat starts up
with a debug port, and the Eclipse debugger should be able to attach to
it.  That's what I had to do with JBoss way back when, and it worked
just fine.  You may have to configure it, and it be as easy as just
clicking on a "Debug project" menu item, but it's pretty easy (or was, I
haven't used Eclipse for a few years now).
-----------------------------------------
------------------------------------------------------------
The information contained in this message is confidential
proprietary property of Nelnet, Inc. and its affiliated 
companies (Nelnet) and is intended for the recipient only.
Any reproduction, forwarding, or copying without the express
permission of Nelnet is strictly prohibited. If you have
received this communication in error, please notify us
immediately by replying to this e-mail.
------------------------------------------------------------

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


Re: Share one singleton across webapps

Posted by Kevin Wilhelm <Ke...@gmx.net>.
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


Re: Share one singleton across webapps

Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
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


RE: Share one singleton across webapps

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Kevin Wilhelm [mailto:KevinWilhelm@gmx.net] 
> Subject: Share one singleton across webapps
> 
> 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?

The class (or jar) to be shared must be placed in Tomcat's lib
directory.  No other configuration should be needed.  Look at the
following for details.
http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

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