tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alessandro Manzoni <>
Subject Re: Initialise application once
Date Sun, 21 Dec 2014 13:10:36 GMT
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.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message