Hi! My suggestion: Encapsulate your C++ call into separate bean class. In each init of servlets: 1. Get the ServletContext (equivalent to 'application' object in jsp) 2. Lookup an object with name *your_name* 3. If there is no binding for *your_name* then create a new instance of your bean class and bind it to ServletContext with *your_name* 4. In servlets doGet(), doPost() retrieve the bound object and use it.
With that approach you have an web application wide useable resource. Every servlet and jsp in the same appl. may use that bean. Clarification for variable sharing: A servlet is by servlet-spec required to be instantiated only once within the container regardless of the number of actual concurrent calls. All call are routed throug the same object. Therefore each static and even non-static variables are shared for each call. For that reason in most cases it's not a good idea to have member-variables in the servlet class, better use provided HttpSession and/or ServletContext objects to store data. Peter Michael Weller wrote: > hi! > what does that c++ function do? i.e. is the return value of the function > depending on some parameters available for each request? > is it depending on some changing data? > if not, simply put an object containing the desired variables as instance > variables into your servlets' context. then the variables are available for > all servlets sharing that context. > > -mw > > ----- Original Message ----- > From: "sanjay" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Friday, January 11, 2002 10:28 AM > Subject: Re: Servlet performance > > | Hi Kaustubh, > | > | Thank you very much for the info. But there are some issues. > | Imagine I have declared a variable in first servlet and instanciated in > | the init method. > | but when I try to use that variable in the second servlet, it would give > | me a compile time error saying that variable is undefined. > | > | Secondly I need the request and response object for the JNI function > | (which i intend to call in init() method) and which is not available in > | the init() method. > | If you need any more explanation on this pl mail me. > | > | Kindly help > | Regards, > | San. > | > | Kaustubh wrote: > | > | > Dear Sanjay, > | > Once u declare an Instance variable in a servlet, it is shared among all > the > | > servlet threads in a multi-threaded model. > | > So declare it as an instance variable and initialize it in the init() > | > method. > | > See if it helps. > | > Actually I had tried it using a simple int variable and it gets shared > among > | > all the servlet threads without making it static. > | > Pls. let me know if this is not the case. > | > Kau. > | > > | > ----- Original Message ----- > | > From: "sanjay" <[EMAIL PROTECTED]> > | > To: <[EMAIL PROTECTED]> > | > Sent: Friday, January 11, 2002 11:17 AM > | > Subject: Servlet performance > | > > | > > Hi all, > | > > I am using servlets with JNI . > | > > I am currently using a JNI function which is being called by most of > my > | > > servlets.This call is made from servlet to fetch data from C++ > | > > domain,which is collected into many arrays which are declared as > public > | > > member variables of my servlet. Is there any method to avoid calling > | > > this JNI function in every other servlet and instead have a single > call > | > > made only in one servlet, but without using static variables to store > | > > the values fetched ? > | > > > | > > > | > > This is basically to avoid increase of memory utilised .What I > observed > | > > is that every access to a servlet increases memory by a certain amount > | > > (100KB), which eventually builds up to 50MB and later gets garbage > | > > collected ,down to 16 MB.I am using Tomcat version 3.2.1. , operating > on > | > > windows NT. > | > > > | > > Kindly Help!!!! > | > > Regards > | > > San. > | > > > | > > > | > > ___________________________________________________________________________ > | > > To unsubscribe, send email to [EMAIL PROTECTED] and include in the > | > body > | > > of the message "signoff SERVLET-INTEREST". > | > > > | > > Archives: http://archives.java.sun.com/archives/servlet-interest.html > | > > Resources: > http://java.sun.com/products/servlet/external-resources.html > | > > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html > | > > > | > > > | > > | > > ___________________________________________________________________________ > | > To unsubscribe, send email to [EMAIL PROTECTED] and include in the > body > | > of the message "signoff SERVLET-INTEREST". > | > > | > Archives: http://archives.java.sun.com/archives/servlet-interest.html > | > Resources: http://java.sun.com/products/servlet/external-resources.html > | > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html > | > | > ___________________________________________________________________________ > | To unsubscribe, send email to [EMAIL PROTECTED] and include in the > body > | of the message "signoff SERVLET-INTEREST". > | > | Archives: http://archives.java.sun.com/archives/servlet-interest.html > | Resources: http://java.sun.com/products/servlet/external-resources.html > | LISTSERV Help: http://www.lsoft.com/manuals/user/user.html > | > | > > ___________________________________________________________________________ > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body > of the message "signoff SERVLET-INTEREST". > > Archives: http://archives.java.sun.com/archives/servlet-interest.html > Resources: http://java.sun.com/products/servlet/external-resources.html > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html -- Peter Huber (IT Consultant) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ evodion Information Technologies GmbH & Co KG Gesch�ftsstelle M�nchen Witneystr.1 D-82008 Unterhaching Telefon: +49-89-66561 - 128 Fax: +49-89-66561 - 199 e-mail: mailto:[EMAIL PROTECTED] Germany Web: http://www.evodion.de ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
