title: How can we use instance variables in RestEasy?
body: <p>I am trying to learn Restful Web Service with RestEasy. I created a Java class and tried to use a instance variable but default scope is Request Scope and after an event, the value of variable is cleaned. How can we use a instance variable in different methods in RestEasy class.
  My code is below:</p>
  
  <pre><code>        /*
       * To change this license header, choose License Headers in Project Properties.
       * To change this template file, choose Tools | Templates
       * and open the template in the editor.
       */
      package restService;
  
      import java.util.HashMap;
      import java.util.Map;
      import javax.ws.rs.Consumes;
      import javax.ws.rs.DELETE;
      import javax.ws.rs.GET;
      import javax.ws.rs.POST;
      import javax.ws.rs.PUT;
      import javax.ws.rs.Path;
      import javax.ws.rs.Produces;
  
      /**
       *
       * @author ilkaygunel
       */
      @Path("/service")
      public class Service {
          Map&lt;Integer, String&gt; employeeMap = new HashMap&lt;&gt;();
  
  
  
      @GET
      @Path("/show")
      @Produces("application/json")
      public Map show()
      {
          return employeeMap;
      }
  
      @POST
      @Path("/addRecord")
      @Consumes("application/json")
      @Produces("application/json")
      public Map addRecord(Employee employee) {
          employeeMap.put(employee.getEmployeeId(), employee.getEmployeeName()+" "+employee.getEmployeeSurname());
          System.out.println("@POST ile işaretlenmiş metoda gelen veri:");
          System.out.println(employee.getEmployeeId());
          System.out.println(employee.getEmployeeName());
          System.out.println(employee.getEmployeeSurname());
  
          System.out.println("---HashMap İçindeki Veri (POST Metodundan)---");
          for (Map.Entry&lt;Integer, String&gt; entry : employeeMap.entrySet()) {
              System.out.println(entry.getKey() +" " +entry.getValue());
          }
          return employeeMap;
      }
  
      @PUT
      @Path("/updateRecord")
      @Consumes("application/json")
      public void updateRecord(Employee employee) {
          System.out.println("@PUT ile işaretlenmiş metoda gelen veri:");
          System.out.println(employee.getEmployeeId());
          System.out.println(employee.getEmployeeName());
          System.out.println(employee.getEmployeeSurname());
  
          System.out.println("HashMap'in Boyutu:"+employeeMap.size());
  
          for(Integer key : employeeMap.keySet()) {
              if(key ==employee.getEmployeeId())
              {
                  System.out.println("Buraya Bak:"+employeeMap.get(key));
                  employeeMap.put(key, employee.getEmployeeName()+" "+employee.getEmployeeSurname());
              }
              break;
          }
  
          System.out.println("---HashMap İçindeki Veri (PUT Metodundan)---");
          for (Map.Entry&lt;Integer, String&gt; entry : employeeMap.entrySet()) {
              System.out.println(entry.getKey() +" " +entry.getValue());
          }
      }
  
      @DELETE
      public void deleteRecord() {
  
      }
  }
  </code></pre>