title: Restlet after few requests generate load on CPU
body: <p>I have problem with API that I am creating. I am using Restlet for create API with json response. First of all I read documentation of restlet and I use simple model that they introduce here: <a href="http://restlet.org/discover/firststeps" rel="nofollow">http://restlet.org/discover/firststeps</a></p>
  
  <p>My code is pretty much the same but some parts. My <strong>ServerResource</strong> is this: </p>
  
  <pre><code>public class CategoriesResource extends ServerResource {
  
      @Get("json")
      public StringRepresentation represent(Representation entity) {
          dbOperations db = new dbOperations();
          db.connect();
  
          Series&lt;Header&gt; responseHeaders = (Series&lt;Header&gt;) getResponse().getAttributes().get("org.restlet.http.headers");
          if (responseHeaders == null) {
          responseHeaders = new Series(Header.class);
          getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
          }
          responseHeaders.add("Access-Control-Allow-Origin", "*"); 
          return new StringRepresentation(db.getCategoriesJson(), MediaType.APPLICATION_JSON);
      }
  
  }
  </code></pre>
  
  <p>I creating json response with gson library in db operations I have lines:</p>
  
  <pre><code>CategoriesGson json = null;
  json = new CategoriesGson(a, b, c, d);
  // databases operations, most getting information from database
  jsonList.add(gson.toJson(json));
  return jsonList.toString();
  </code></pre>
  
  <p>Main problem is with CPU load when I press F5 after few times I get a lot of load on CPU. I was searching problem with that and I was able to do dump of thread is giving this usage. </p>
  
  <pre><code>Restlet-9860934" prio=10 tid=0x8828d000 nid=0x12ee runnable [0x87f89000]
     java.lang.Thread.State: RUNNABLE
      at java.lang.String.valueOf(String.java:2854)
      at java.lang.StringBuilder.append(StringBuilder.java:128)
      at org.restlet.engine.connector.Way.toString(Way.java:594)
      at java.lang.String.valueOf(String.java:2854)
      at java.lang.StringBuilder.append(StringBuilder.java:128)
      at org.restlet.engine.connector.Way.onSelected(Way.java:471)
      at org.restlet.util.SelectionRegistration.onSelected(SelectionRegistration.java:325)
      at org.restlet.engine.connector.Connection.onSelected(Connection.java:612)
      - locked &lt;0x937a7550&gt; (a java.nio.HeapByteBuffer)
      at org.restlet.util.SelectionRegistration.onSelected(SelectionRegistration.java:325)
      at org.restlet.engine.connector.ConnectionController.onSelected(ConnectionController.java:219)
      at org.restlet.engine.connector.ServerConnectionController.onSelected(ServerConnectionController.java:99)
      at org.restlet.engine.connector.ConnectionController.selectKeys(ConnectionController.java:308)
      at org.restlet.engine.connector.ConnectionController.doRun(ConnectionController.java:171)
      at org.restlet.engine.connector.Controller.run(Controller.java:159)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      at java.util.concurrent.FutureTask.run(FutureTask.java:166)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:724)
  </code></pre>
  
  <p>This is restlet thread and I think this is it fault. I have not idea how I can fix that. I was searching for this issue and I found only issue 386 and 794 on github. If someone have some idea how I can fix that please let me know.</p>