If I understand the Spring lifecycle, at least semi-correctly, then each singleton bean in my config file (or files) is instantiated once at startup and that same instance is supplied any time the bean is requested. It seems like there should be all kinds of issues with the controller beans (and any other singleton beans, for that matter) being used in multiple threads, especially in a web application, yet I haven't seen this issue discussed anywhere.
Do I need to avoid instance variables in my singleton beans (esp controllers), or at least synchronize access to them? It seems like not using instance variables is probably the best way to go in any case, at least with controllers. Come to think of it, most of my Spring-managed beans don't have much use for instance variables in any case...
Along the same lines, shouldn't the controller methods be synchronized to prevent multiple threads from messing with local variables?
I'm sure I'm missing something here - I'm not very familiar with threading issues in general. If anyone could shed some light on the issues, particularly in a web application, with controller and singleton beans and multithreading I would really appreciate it! Thanks in advance!
Brian St.Clair


Reply With Quote