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