We have a spring application (single-threaded by design). We want to adapt it to be multi-threaded. One Idea was to create a parent thread and spawn different threads which would instantiate their own app context and run in parallel. (Memory and cpu are not a concern as of now). I am not sure how singletons are realized in spring. Does spring use a static reference and return this or uses some sort of cache/map (which is non-static/non-singleton and context specific) where it does a lookup? This would help me decide whether or not to change the config-xml. Any ideas please.
Share
Spring
singletonbeans are instantiated once per application context. That is, if you create many application contexts from the same config, they’ll have different instances of singleton beans.If you want them to share a single instance of a singleton bean, you can declare it in the parent application context and supply your multiple contexts with that parent context when you create them.