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.
Spring singleton
beans 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.
Why to you need multiple application contexts to make an application multi-threaded? Multiple threads can use the same context perfectly well.
Update: Take a look at spring batch
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With