Are Spring Controllers Thread-Safe

前端 未结 4 1366
你的背包
你的背包 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:42

    To answer the question in the title, "Are Spring Controllers Thread-Safe", Spring Controllers are singletons, therefore they SHOULD be implemented in a thread safe manner but it's up to you to ensure that your implementation is ACTUALLY thread safe.

    In the code you post you should be fine since as others have pointed out, GSON is thread safe.

提交回复
热议问题