Using special auto start servlet to initialize on startup and share application data

Viewed 17080

I need to get some configuration and connect to external resources/objects/systems somewhere and store it in application scope.

I can see two ways to setup my application:

  • Overriding the init() in the existing servlets and required code there and keeping all constructed objects inside that same servlet.
  • Having some kind of an initialisation servlet and using its init() to do the work. Then storing created objects in ServletContext to share it with my other servlets.

Which out of above is better approach? Is there any better way to share objects between servlets? Calling them directly from one another or so...?

1 Answers
Related