Are Spring Controllers Thread-Safe

前端 未结 4 1353
你的背包
你的背包 2021-02-05 18:21

I came upon this Controller example, and am wondering if it is thread-safe? I am wondering specifically about the gson instance variable.

import org.springframe         


        
4条回答
  •  遥遥无期
    2021-02-05 18:35

    Just like servlets controller request handler methods are also not thread safe. Ie a multiple request to /test may make many threads execute test method.

    In your example you dont have to worry about thread safety as gson.toJson(results) is the only operation on gson and seems like it wont alter the state of that object.

提交回复
热议问题