Re: Initialise application once

2014-12-22 Thread Terence M. Bandoian

On 12/21/2014 9:14 AM, Fabio Ricci wrote:

Yes that made it

THANK YOU very much!!!
Grazie mille!

Cheers
Fabio


Am 21.12.14 um 14:10 schrieb Alessandro Manzoni:

Il 21.12.2014 13.38, Fabio Ricci ha scritto:

Dear community

I developed a tomcat JSP servlet which - say - instantiates a class, 
work with that class and gives some output back to the calling user 
in the browser.


My point is instantiating the class ***once*** for every requests 
coming after this instantiation. The reason is: the class loads 
several components into memory and I would like not to do this at 
every call of this JSP servlet but just once.


Where shell I put the initializing code for the heavy components? 
Is this possible?


Thank you very much in advance!
Fabio

Try putting an attribute inside the servlet contex in a lazy way, 
that will be in the scope of the whole application inside the same 
VM.E.g.:

Object grosso = getServletContext().getAttribute(GROSSO);
if (grosso == null) {
   grosso = new Grosso();
   getServletContext().setAttribute(GROSSO, grosso);
}
If you want to limit the scope to a single session, put the same as a 
session attribute.



You could also use a singleton that initializes itself in the same way.  
Either way, the object and initialization should be thread safe.


Happy Holidays!

-Terence Bandoian


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Initialise application once

2014-12-21 Thread Fabio Ricci
Dear community

I developed a tomcat JSP servlet which - say - instantiates a class,
work with that class and gives some output back to the calling user in
the browser.

My point is instantiating the class ***once*** for every requests coming
after this instantiation. The reason is: the class loads several
components into memory and I would like not to do this at every call of
this JSP servlet but just once.

Where shell I put the initializing code for the heavy components? Is
this possible?

Thank you very much in advance!
Fabio



signature.asc
Description: OpenPGP digital signature


Re: Initialise application once

2014-12-21 Thread Alessandro Manzoni

Il 21.12.2014 13.38, Fabio Ricci ha scritto:

Dear community

I developed a tomcat JSP servlet which - say - instantiates a class, 
work with that class and gives some output back to the calling user in 
the browser.


My point is instantiating the class ***once*** for every requests 
coming after this instantiation. The reason is: the class loads 
several components into memory and I would like not to do this at 
every call of this JSP servlet but just once.


Where shell I put the initializing code for the heavy components? Is 
this possible?


Thank you very much in advance!
Fabio

Try putting an attribute inside the servlet contex in a lazy way, that 
will be in the scope of the whole application inside the same VM.E.g.:

Object grosso = getServletContext().getAttribute(GROSSO);
if (grosso == null) {
   grosso = new Grosso();
   getServletContext().setAttribute(GROSSO, grosso);
}
If you want to limit the scope to a single session, put the same as a 
session attribute.


Re: Initialise application once

2014-12-21 Thread Yaragalla Muralidhar
servlet context is exactly what u need.

*Thanks and Regards,*
Muralidhar Yaragalla.

*http://yaragalla.blogspot.in/ http://yaragalla.blogspot.in/*

On Sun, Dec 21, 2014 at 6:40 PM, Alessandro Manzoni 
manzoni.alessand...@gmail.com wrote:

 Il 21.12.2014 13.38, Fabio Ricci ha scritto:

  Dear community

 I developed a tomcat JSP servlet which - say - instantiates a class, work
 with that class and gives some output back to the calling user in the
 browser.

 My point is instantiating the class ***once*** for every requests coming
 after this instantiation. The reason is: the class loads several components
 into memory and I would like not to do this at every call of this JSP
 servlet but just once.

 Where shell I put the initializing code for the heavy components? Is
 this possible?

 Thank you very much in advance!
 Fabio

  Try putting an attribute inside the servlet contex in a lazy way, that
 will be in the scope of the whole application inside the same VM.E.g.:
 Object grosso = getServletContext().getAttribute(GROSSO);
 if (grosso == null) {
grosso = new Grosso();
getServletContext().setAttribute(GROSSO, grosso);
 }
 If you want to limit the scope to a single session, put the same as a
 session attribute.



Re: Initialise application once

2014-12-21 Thread Fabio Ricci
Yes that made it

THANK YOU very much!!!
Grazie mille!

Cheers
Fabio


Am 21.12.14 um 14:10 schrieb Alessandro Manzoni:
 Il 21.12.2014 13.38, Fabio Ricci ha scritto:
 Dear community

 I developed a tomcat JSP servlet which - say - instantiates a class,
 work with that class and gives some output back to the calling user
 in the browser.

 My point is instantiating the class ***once*** for every requests
 coming after this instantiation. The reason is: the class loads
 several components into memory and I would like not to do this at
 every call of this JSP servlet but just once.

 Where shell I put the initializing code for the heavy components?
 Is this possible?

 Thank you very much in advance!
 Fabio

 Try putting an attribute inside the servlet contex in a lazy way, that
 will be in the scope of the whole application inside the same VM.E.g.:
 Object grosso = getServletContext().getAttribute(GROSSO);
 if (grosso == null) {
grosso = new Grosso();
getServletContext().setAttribute(GROSSO, grosso);
 }
 If you want to limit the scope to a single session, put the same as a
 session attribute.


-- 
Kind regards / Meilleures salutations / Freundliche Grüsse
/Fabio Ricci/
semweb  

Semantic Web Technologies · Records Management
Software systems · ICT coaching · ICT Projects leading  



*www.semweb.ch* http://semweb.ch





Weinmanngasse 26
CH-8700 Küsnacht ZH (Switzerland)





/Tel./



+41 (076) 5281961
+39 (389) 0681334

/Skype:/



*semweb-llc* http://myskype.info/semweb-llc

*Confidentiality Warning*: This message and any attachments are intended
only for the use of the intended recipients, are confidential and maybe
privileged. If you are not the intended recipient, you are hereby
notified that any review, retransmission, conversion to hard copy,
copying, circulation or other use of this message and any attachments is
strictly prohibited. If you are not the intended recipient, please
notify the sender immediately by return email, and delete this message
and any attachments from your system. Thank you.



signature.asc
Description: OpenPGP digital signature