Singletons should be JVM based.
> > The way management server works is that the container (jetty, tomcat, jboss > and whatnot) reads a web.xml (ref: client/WEB-INF/) and starts them up. > Based on some url pattern a http request is rerouted to them and handled. > > What is the use of com.cloud.servlet.RegisterCompleteServlet and do we > need it? >From the url mapping it seems to be used for mycloud which is obsolete I think > > <servlet> > <servlet-name>registerCompleteServlet</servlet-name> > > <servlet-class>com.cloud.servlet.RegisterCompleteServlet</servlet-class> > </servlet> > > Singletons are per class loader basis and not JVM, so when a servlet > initialises > ComponentLocator (not sure if we would have an issue on javelin, it's got > spring DI) which in turn loads other things, and as the compiled binaries are > in > the same war artifact, all contexts would share the same static variable, the > problem is ComponentLocator would have the plugin maps which is a > HashMap (_pluginsMap is non-static) and therefore would be different for > each servlet. _pluginsMap is non-static but s_locators is. ComponentLocator. getLocator which essentially calls ComponentLocator .getLocatorInternal will synchronize on s_locators, that means ComponentLocators having the same name should not be initialized twice. So pluggable services twice initialized should be caused by some other issue. > > The issue I've faced myself is that the pluggable services (plugins) which > should have been singleton are per context and the plugins would be > initialised twice (putting a logging statement in one of the plugins, viz. > plugins/api/discovery confirmed it). > > Regards. I heard that we were adopting jersey or whatever advanced library for http API. Then there is no reason to use multiple servlets any more, as handling different url mapping is nature for these libraries. And speaking of Spring DI. There should be only one ServletContextListener where Spring IOC gets initialized/destroyed in future. I don't know where does our Spring IOC get initialized, but if ComponentLocator is loaded by spring with a name other than ManagementServer.Name, then there would be two copies of ComponentLocator which load all plugins twice