These suggestions seems do to exactly what I want in a structured way. I
just need to read more about how to set up the application and the context
in the correct way. Do you have any example?

Regards,
Andreas

-----Original Message-----
From: Reynir H�bner [mailto:[EMAIL PROTECTED]
Sent: den 7 mars 2003 11:54
To: Tomcat Users List
Subject: RE: Share Java resources between two (or more) servlets


Hi,

See intermixed.


> -----Original Message-----
> From: Andreas Bystr�m [mailto:[EMAIL PROTECTED]
> Sent: 7. mars 2003 10:20
> To: Tomcat Users
> Subject: Share Java resources between two (or more) servlets
>
>
> Hi all!
>
> I'm writing an application that uses (for now) 4 different
> servlets. I would like all these servlets to share some java
> singelton object. Is this possible? Do all servlets share the
> same jvm instance and thereby uses the same singelton object?

Sure no problem as long as the singleton object is in the same classloader
scope it should not be a problem.
Each application is loaded with sepperate classloaders, so as long as the
servlets are in the same application and the singleton is in it's classpath
too it works.

>
> I have one servlet that is set to load-on-startup, this
> servlet will create the java object (db connections and other
> stuff) that I want all servlets to share later on. This
> servlet is not used anymore, it hust listens for shutdown and
> will not receive any requests. Is this how you should solve a
> initialization problem or is there some other way?

Use a ServletContextListener to startup such objects, rather than the
load-on-startup method of servlets.
It has some benefits doing it that way, like, you can do some cleanup (if
needed) when the context is destroyed.

> When I run my application I start this servlet  (servlet1) as
> above. But when I then invoke another servlet, servlet2,
> (that is not set to
> load-on-startup) there is a strange behavior. Using my traces
> I can read that it first invokes init on servlet1 again and
> then init on servlet2. If I then sends a first reuquest to
> servlet3 it just does init on servlet3. If I instead had sent
> the first request to 3 before the first request to servlet2
> it is the same behavior but vice versa. when the request
> comes to servlet3 it does init on first 1 nd then 3. The
> request to servlet 2 now just incokes init on servlet2. Have
> anyone a clue of you it can be like this?

Not really...
How are you "sending the requests" ?
-reynir

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to