Servlet goes through init() twice when Tomcat starts
843840Sep 26 2001 — edited Oct 24 2001I am using a servlet to initialize a Singleton object. In the ROOT\WEB-INF\web.xml file, I set load-on-startup to 1. The servlet gets loaded and the init method is called. However, the init() gets called twice with two different ServletContext objects. Thus, I end up creating two of my Singleton objects -- not good. I tried using a static flag as a member of the servlet class to ensure that the Singleton object gets created only once, but that flag is not being saved properly between the two calls (maybe because there are two different ServletContext's, and thus two separate applications running?). Any ideas?