title: Are Spring Controllers Thread-Safe
body: <p>I came upon this Controller example, and am wondering if it is thread-safe?  I am wondering specifically about the gson instance variable.</p>
  
  <pre><code>import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import com.google.gson.Gson;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.HashMap;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  @Controller
  public class TestController {
  
      private final Gson gson = new Gson();
  
      @RequestMapping(value = "/test", method = RequestMethod.GET)
      public void test(HttpServletResponse res, HttpServletRequest req) throws IOException {
          HashMap&lt;String, String&gt; hm = new HashMap();
          res.getWriter().print(gson.toJson(results));
          res.getWriter().close();
      }
  }
  </code></pre>