I have a class that I want to instantiate at startup. It does concurrent stuff and has开发者_如何学编程 to be visible for all incoming requests. Placing it in the ServletContext should be the right way to go.
I don't care about bottlenecks, all requests have to work on the same data.
But how can I tell my Webserver to load this class once at startup and place it into the context?
For Strings there is the setInitParameter, but can't we do the same for objects?
You might want to look at a ServletContexListener and store your Object in context when the context is initalized. You can get the ServletContext from the passed ServletContextEvent.
精彩评论