I wish to initialize a worldwide demonstration of a category before my Tomcat server completes startup and starts to provide my servlets. If the service in some way fails initialization, I would like the whole startup sequence to fail too (or as near for this as you possibly can it might be pointless for that server to become running otherwise). What's the easiest way I'm able to make this happen?

Each web application includes a ServletContext connected by using it. The ServletContext object is produced once the application is began and it is destroyed once the application is shut lower. A ServletContext includes a global scope and is comparable to a worldwide variable within an application.


complete explanation here


One factor that you can do portably would be to implement a servlet that initializes all you need in the init() method (and perhaps call System.exit() whether it fails, i don't know for those who have permission to get this done in Tomcat). You would then load it using <load-on-startup> inside your web.xml to specify initialization order.