Varun
Varun

Reputation: 107

Static methods with Spring MVC and tomcat

What will happen if I use static methods (say from a utility class that I created) with Spring MVC. Moreover, my static methods are not synchronized. What may happen if multiple requests call the same method at same time.

Upvotes: 5

Views: 1166

Answers (1)

Zilvinas
Zilvinas

Reputation: 5578

Its OK to use static methods if you know what you're doing. If in your static method you're using only local variables ( not fields in a class ) you should then be thread-safe too. Otherwise - it is up to you do handle the synchronization and locking to keep data consistent.

Spring has a limitation that you cannot use static on setters of spring beans.

Upvotes: 1

Related Questions