Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Servlet goes through init() twice when Tomcat starts

843840Sep 26 2001 — edited Oct 24 2001
I 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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 21 2001
Added on Sep 26 2001
5 comments
662 views