Tuesday, 19 April 2011

Why to use the HttpServlet Init method to perform expensive operations that need only be done once?

 Because the servlet init() method is invoked when servlet instance is loaded, it is the perfect location to carry out expensive operations that need only be performed during initialization. By definition, the init() method is thread-safe. The results of operations in the HttpServlet.init() method can be cached safely in servlet instance variables, which become read-only in the servlet service method.

No comments:

Post a Comment