Re: Two instances of servlet gets created

2003-01-03 Thread Mohit Garg
In my case if the request comes from within the same context, it works fine
and does not creates two instances.

But if I have another application deployed in different context and sending
a request to my servlet, then, there is new instance of servlet gets
created.

I tried with one example,  creating link in HTML file to call my servlet.
And tried to call my servlet by copying this file into both the contexts and
then clicking this link

a href=../servlet/wf.Handler.user?wfuser_id=TimedTesting_1Dummy workflow
TimedWfTesting_1/a
wf.Handler.user is the name of my servlet.

The result remain same. For the different context, another instance gets
created for my servlet.

Is this the behaviors of servlets ? How can I control it for only one
instance creation ?


- Original Message -
From: Gavin, Rick [EMAIL PROTECTED]
To: Tomcat Users List [EMAIL PROTECTED]
Sent: Thursday, January 02, 2003 7:37 PM
Subject: RE: Two instances of servlet gets created


 I have also been seeing this, I think since I have upgraded
 from 4.1.12.  I have a startup servlet that creates a
 singleton object i use for system properties, and it calls
 the createInstance of the singleton twice at startup now.

 Rick

 -Original Message-
 From: Mohit Garg [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, January 02, 2003 3:52 AM
 To: Tomcat Users List
 Subject: Two instances of servlet gets created


 I have startup servlet for which one instance is created as soon as my
 tomcat starts. But on the first request to the servlet there is another
 instance created. i.e Another time init() is called for the servlet.


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

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



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




RE: Two instances of servlet gets created

2003-01-03 Thread Cox, Charlie


 -Original Message-
 From: Mohit Garg [mailto:[EMAIL PROTECTED]]
 Sent: Friday, January 03, 2003 5:42 AM
 To: Tomcat Users List
 Subject: Re: Two instances of servlet gets created
 
 
 In my case if the request comes from within the same context, 
 it works fine
 and does not creates two instances.
 

This is correct.

 But if I have another application deployed in different 
 context and sending
 a request to my servlet, then, there is new instance of servlet gets
 created.
 

This is also correct. Each context is loading your servlet into its own
classloader, so it doesn't know about the other web apps(context)'s classes.
You can move your common functionality(singleton,etc) into its own class,
which you can put in /common/lib (or /common/classes) where it will only be
loaded once and shared for all web apps.

you may want to review the classloading document:
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/class-loader-howto.html

Charlie

 I tried with one example,  creating link in HTML file to call 
 my servlet.
 And tried to call my servlet by copying this file into both 
 the contexts and
 then clicking this link
 
 a 
 href=../servlet/wf.Handler.user?wfuser_id=TimedTesting_1Dum
 my workflow
 TimedWfTesting_1/a
 wf.Handler.user is the name of my servlet.
 
 The result remain same. For the different context, another 
 instance gets
 created for my servlet.
 
 Is this the behaviors of servlets ? How can I control it for only one
 instance creation ?
 
 
 - Original Message -
 From: Gavin, Rick [EMAIL PROTECTED]
 To: Tomcat Users List [EMAIL PROTECTED]
 Sent: Thursday, January 02, 2003 7:37 PM
 Subject: RE: Two instances of servlet gets created
 
 
  I have also been seeing this, I think since I have upgraded
  from 4.1.12.  I have a startup servlet that creates a
  singleton object i use for system properties, and it calls
  the createInstance of the singleton twice at startup now.
 
  Rick
 
  -Original Message-
  From: Mohit Garg [mailto:[EMAIL PROTECTED]]
  Sent: Thursday, January 02, 2003 3:52 AM
  To: Tomcat Users List
  Subject: Two instances of servlet gets created
 
 
  I have startup servlet for which one instance is created as 
 soon as my
  tomcat starts. But on the first request to the servlet 
 there is another
  instance created. i.e Another time init() is called for the servlet.
 
 
  --
  To unsubscribe, e-mail:
  mailto:[EMAIL PROTECTED]
  For additional commands, e-mail:
  mailto:[EMAIL PROTECTED]
 
  --
  To unsubscribe, e-mail:
 mailto:[EMAIL PROTECTED]
  For additional commands, e-mail:
 mailto:[EMAIL PROTECTED]
 
 
 
 --
 To unsubscribe, e-mail:   
mailto:[EMAIL PROTECTED]
For additional commands, e-mail:
mailto:[EMAIL PROTECTED]

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




Re: Two instances of servlet gets created

2003-01-03 Thread Jacob Kjome

New instances of any servlet will be created for as many times as the 
servlet is named differently.  For instance, all these refer to the same 
servlet, but each will be a separate instance

servlet
servlet-nameMyServletName/servlet-name
servlet-classcom.mypackage.MyServlet/servlet-class
/servlet
servlet-mapping
servlet-nameMyServletName/servlet-name
url-pattern/mymapping/url-pattern
/servlet-mapping


http://localhost:8080/mycontext/mymapping

http://localhost:8080/mycontext/servlet/MyServletName

http://localhost:8080/mycontext/servlet/com.mypackage.MyServlet

What is at issue is the invoker servlet which is mapped to /servlet/* in 
Tomcat's conf/web.xml.  It will create these separate servlet 
instances.  If you don't like this behavior, then disabled the invoker 
servletwhich is disabled by default in recent releases for security 
reasons.

Jake


At 04:11 PM 1/3/2003 +0530, you wrote:
In my case if the request comes from within the same context, it works fine
and does not creates two instances.

But if I have another application deployed in different context and sending
a request to my servlet, then, there is new instance of servlet gets
created.

I tried with one example,  creating link in HTML file to call my servlet.
And tried to call my servlet by copying this file into both the contexts and
then clicking this link

a href=../servlet/wf.Handler.user?wfuser_id=TimedTesting_1Dummy workflow
TimedWfTesting_1/a
wf.Handler.user is the name of my servlet.

The result remain same. For the different context, another instance gets
created for my servlet.

Is this the behaviors of servlets ? How can I control it for only one
instance creation ?


- Original Message -
From: Gavin, Rick [EMAIL PROTECTED]
To: Tomcat Users List [EMAIL PROTECTED]
Sent: Thursday, January 02, 2003 7:37 PM
Subject: RE: Two instances of servlet gets created


 I have also been seeing this, I think since I have upgraded
 from 4.1.12.  I have a startup servlet that creates a
 singleton object i use for system properties, and it calls
 the createInstance of the singleton twice at startup now.

 Rick

 -Original Message-
 From: Mohit Garg [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, January 02, 2003 3:52 AM
 To: Tomcat Users List
 Subject: Two instances of servlet gets created


 I have startup servlet for which one instance is created as soon as my
 tomcat starts. But on the first request to the servlet there is another
 instance created. i.e Another time init() is called for the servlet.


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

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



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



RE: Two instances of servlet gets created

2003-01-03 Thread Jacob Kjome

Charlie is right.  In the response I gave to this thread, I was assuming 
your were talking about servlets in the same context.  Sorry, didn't read 
carefully.  Anyway, my comments still apply when talking about as single 
context.

Jake

At 12:03 PM 1/3/2003 -0500, you wrote:


 -Original Message-
 From: Mohit Garg [mailto:[EMAIL PROTECTED]]
 Sent: Friday, January 03, 2003 5:42 AM
 To: Tomcat Users List
 Subject: Re: Two instances of servlet gets created


 In my case if the request comes from within the same context,
 it works fine
 and does not creates two instances.


This is correct.

 But if I have another application deployed in different
 context and sending
 a request to my servlet, then, there is new instance of servlet gets
 created.


This is also correct. Each context is loading your servlet into its own
classloader, so it doesn't know about the other web apps(context)'s classes.
You can move your common functionality(singleton,etc) into its own class,
which you can put in /common/lib (or /common/classes) where it will only be
loaded once and shared for all web apps.

you may want to review the classloading document:
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/class-loader-howto.html

Charlie

 I tried with one example,  creating link in HTML file to call
 my servlet.
 And tried to call my servlet by copying this file into both
 the contexts and
 then clicking this link

 a
 href=../servlet/wf.Handler.user?wfuser_id=TimedTesting_1Dum
 my workflow
 TimedWfTesting_1/a
 wf.Handler.user is the name of my servlet.

 The result remain same. For the different context, another
 instance gets
 created for my servlet.

 Is this the behaviors of servlets ? How can I control it for only one
 instance creation ?


 - Original Message -
 From: Gavin, Rick [EMAIL PROTECTED]
 To: Tomcat Users List [EMAIL PROTECTED]
 Sent: Thursday, January 02, 2003 7:37 PM
 Subject: RE: Two instances of servlet gets created


  I have also been seeing this, I think since I have upgraded
  from 4.1.12.  I have a startup servlet that creates a
  singleton object i use for system properties, and it calls
  the createInstance of the singleton twice at startup now.
 
  Rick
 
  -Original Message-
  From: Mohit Garg [mailto:[EMAIL PROTECTED]]
  Sent: Thursday, January 02, 2003 3:52 AM
  To: Tomcat Users List
  Subject: Two instances of servlet gets created
 
 
  I have startup servlet for which one instance is created as
 soon as my
  tomcat starts. But on the first request to the servlet
 there is another
  instance created. i.e Another time init() is called for the servlet.
 
 
  --
  To unsubscribe, e-mail:
  mailto:[EMAIL PROTECTED]
  For additional commands, e-mail:
  mailto:[EMAIL PROTECTED]
 
  --
  To unsubscribe, e-mail:
 mailto:[EMAIL PROTECTED]
  For additional commands, e-mail:
 mailto:[EMAIL PROTECTED]
 


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

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



Two instances of servlet gets created

2003-01-02 Thread Mohit Garg
I have startup servlet for which one instance is created as soon as my
tomcat starts. But on the first request to the servlet there is another
instance created. i.e Another time init() is called for the servlet.


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




Re: Two instances of servlet gets created

2003-01-02 Thread Andreas Probst
Hi,

do you call your servlet by the pattern defined in web.xml or by 
the full path with invoker servlet? 

I once read, that using the invoker servlet means creating a new 
instance of your servlet. Maybe that's what causes the second 
init().

Hope this helps

Andreas


On 2 Jan 2003 at 17:22, Mohit Garg wrote:

 I have startup servlet for which one instance is created as soon
 as my tomcat starts. But on the first request to the servlet
 there is another instance created. i.e Another time init() is
 called for the servlet.
 
 


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




RE: Two instances of servlet gets created

2003-01-02 Thread Gavin, Rick
I have also been seeing this, I think since I have upgraded 
from 4.1.12.  I have a startup servlet that creates a 
singleton object i use for system properties, and it calls
the createInstance of the singleton twice at startup now.

Rick

-Original Message-
From: Mohit Garg [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 02, 2003 3:52 AM
To: Tomcat Users List
Subject: Two instances of servlet gets created


I have startup servlet for which one instance is created as soon as my
tomcat starts. But on the first request to the servlet there is another
instance created. i.e Another time init() is called for the servlet.


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

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