title: Spring/REST Resource/Service scope
body: <p>I am trying to figure out what is the best "scope" for a java REST webservice using jersey and spring.</p>
  
  <p>I have a class defined like so:</p>
  
  <pre><code>@Path("/mypath")
  @Component
  @Scope("request")  // Or should this be @Scope("singleton")
  public final class MyResource {
  
  }
  </code></pre>
  
  <p>What I want to know is, should this be defined as request or singleton scope.  I think it should be singleton scope because it is stateless.  My thought is that this would be better performance wise since it is only created once, not a big performance gain but a small one.</p>
  
  <p>However, someone expressed concern that there could be a performance loss/hit with a singleton because it will have to handle the requests from every thread, but my thought is that since there is no locking/synchronization then each thread will be able to call the method without being blocked, so no bottleneck.</p>
  
  <p>I guess my question is two pronged:</p>
  
  <ol>
  <li><p>Is singleton scope the best scope for stateless web services</p></li>
  <li><p>Is there a performance loss when using a singleton because it has to
  handle multiple threads at once?</p></li>
  </ol>
  
  <p>Thanks.</p>