PDA

View Full Version : Question regarding all Controllers...


senthilnathan74
May 19th, 2007, 05:50 PM
Hi,
I'm pretty new to the Spring and currently i'm involved in the development of a project using Spring MVC. I read in few articles saying that Controllers are not thread-safe. In other words same instance of controller will serve multiple requests. Is this true? If so then we shouldn't declare instance variables.

Thanks a lot!!!
Senthil.

Jörg Heinicke
May 19th, 2007, 09:44 PM
The controllers coming with Spring ARE thread-safe. If you extend one of them you have to make sure that your implementation preserves thread-safeness. Controllers should really be implemented in a thread-safe way.

Jörg

senthilnathan74
May 20th, 2007, 11:16 AM
The controllers coming with Spring ARE thread-safe. If you extend one of them you have to make sure that your implementation preserves thread-safeness. Controllers should really be implemented in a thread-safe way.

Jörg

Thanks for your response. So in controllers we should not declare instance variables, or global objects which should not be shared between users/requests.

Marten Deinum
May 21st, 2007, 03:55 AM
that is correct, if you do that your Controller will become thread-unsafe.