title: REST WebServise - how to use service like a singleton?
body: <p>My rest application contains a service and I need to make this service to act like a singleton to save a state of the service.</p>
  
  <p>a service:</p>
  
  <pre><code>@Path("/script")
  public class ScriptEngineProvider {
  
  private AtomicInteger idCounter;
  
  public ScriptEngineProvider() {
      System.out.println("before AtomicInteger");
      idCounter = new AtomicInteger();
  }
  
  @POST
  public Response executeScript( String x ) {
      idCounter.incrementAndGet();
      System.out.println("counter " + idCounter);
      ...
  </code></pre>
  
  <p>a client besides all other code has:</p>
  
  <pre><code>WebTarget webTarget = client.target("http://localhost:8080/NashornEngine/rest").path("script");
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
  </code></pre>
  
  <p>With the above configuration the application works but with every request the variable <code>idCounter</code> creates so <code>idCounter</code> is allways <code>1</code>.</p>
  
  <p>Now I use next class to make the <code>ScriptEngineProvider</code> to be a singleton:</p>
  
  <pre><code>@ApplicationPath("/services")
  public class NashornApplication extends Application {
      private Set&lt;Object&gt; singletons = new HashSet&lt;Object&gt;();
      public NashornApplication() {
          singletons.add(new ScriptEngineProvider());
      }
      @Override
      public Set&lt;Object&gt; getSingletons() {
          return singletons;
      }
  }
  </code></pre>
  
  <p>The problem is that I get <code>The requested resource is not available</code> with request:</p>
  
  <pre><code>//path services was added
  WebTarget webTarget = client.target("http://localhost:8080/NashornEngine/rest").path("services").path("script");
  </code></pre>
  
  <p>What is the problem with this config?</p>