title: Store temporary data in a Spring Controller
body: <p>I'm wondering if I could store temporary data in a class attribute of a <code>Controller</code>.
  My doubt is about the concurrency calls. Let us, for example, consider the following code:</p>
  
  <pre><code>@Controller
  public class TestController {
      @Autowired
      private TestService testService;
  
      @Autowired
      private OtherService otherService;
  
      private final HashMap&lt;Integer, Test&gt; testMap = new HashMap&lt;Integer, Test&gt;();
  
      @RequestMapping(value = "test")
      @ResponseBody
      public List&lt;Test&gt; test() {
          List&lt;Test&gt; list = new ArrayList&lt;Test&gt;();
          for (final OtherTest otherTest : otherService.getAll()) {
              Integer key = otherTest.getId();
              final Test t;
              if(testMap.containsKey(key)) {
                  t = testMap.get(key);
              } else {
                  t = testService.getByOtherTestId(key);
              }
              list.add(t);
          }
      }
  }
  </code></pre>
  
  <p>I know that <code>Controllers</code> are <code>Beans</code>, and I know that <code>Beans</code> are <code>Singleton</code>, so:</p>
  
  <p>What happen if two users call the <code>test</code> method at the same time?
  Each one of them read/write the same <code>testMap</code> object?
  When the <code>testMap</code> object lose its scope and will be re-instantiated?</p>
  
  <p>Thanks</p>