title: Java Program High CPU usage
body: <p>I wrote a java program which queries oracle database and converts it to object using <code>beanutils</code> </p>
  
  <p>During <code>Load Testing</code> 
  I found high CPU usage.</p>
  
  <p>Outline of the program is:</p>
  
  <pre><code>List&lt;Map&lt;String, List&gt;&gt; rows = queryList(query, new Object[]{params..});
  while(rows.hasNext()){
     beanutils.setProperty(obj, field, row.get("some column name"));  
  }
  </code></pre>
  
  <p>DB returns approximately <code>350</code> rows.</p>
  
  <p>Executing the program makes my CPU to spike 100%.</p>
  
  <p>Removing the beanutils and testing query - CPU usage was 30%.</p>
  
  <p>Now if I remove the <code>beanutils.setProperty</code> and use <code>getters and setters</code> CPU is not spiking(50%)</p>
  
  <p>In <code>jvisualvm sampler</code> I find:</p>
  
  <pre><code>oracle.net.ns.Packet.receive()
  org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer()
  org.apache.tomcat.util.net.NioEndpoint$Poller.run()
  </code></pre>
  
  <p>taking most of <code>Self time CPU</code></p>
  
  <p>I used <code>jmeter</code> to load test ( 20 concurrent requests ).
  BaseLine of the <code>jvisualvm</code> graph is 0%. So definitely because of this load test only cpu is spiking.</p>
  
  <p>Is it <code>reflection</code> that is causing high CPU usage?</p>
  
  <p>Does executing a query eg: <code>queryforlist</code> takes CPU utilization to increase.</p>
  
  <p>Later if my computation increases then should I reduce the number of threads accessing this api as it will spike my cpu again.</p>
  
  <p>Thanks in advance.</p>