Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 624
user2632932 Avatar asked Nov 12 '22 22:11

user2632932


1 Answers

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.

like image 123
Zilvinas Avatar answered Nov 15 '22 05:11

Zilvinas