title: How to solve java.lang.OutOfMemoryError: Java heap space error
body: <p>I am working in real time project.</p>
  
  <p>Working:
  I am getting data from twitter and moving the output to cassandra database and then using Testrestfull webservice i am getting the output in json format. And then finally outputs are displayed in wep page. i am using glass fish server to connect web service and web page. it is an real time project so i am refreshing my page in every 5 second.</p>
  
  <p>First few seconds i am not getting any error it works fine after 5 to 10 minutes i am getting this error in glass fish server.</p>
  
  <p>Error:
  WARNING:   StandardWrapperValve[genric.ApplicationConfig]: Servlet.service() for servlet genric.ApplicationConfig threw exception
  java.lang.OutOfMemoryError: Java heap space</p>
  
  <p>I dont know why i am getting this error and how to solve this.
  Can any one help me.</p>
  
  <p>This is my webservice code:</p>
  
  <pre><code>public String gettweets(String st)
  {
   cluster=Cluster.builder().addContactPoint("localhost").build();    
   session=cluster.connect("space");
   String query ="select * from tweet_count where createdtime='"+st+"' allow filtering;";
   ResultSet result = session.execute(query);
   String text = "[";
   for(Row r : result){
      System.out.println(r.getString("tag_name"));
     text+="{\""+"x"+"\":\""+r.getString("tag_name")+"\",\""+"y"+"\":\""+r.getInt("count")+"\"},";
  
  }
  text=text.substring(0,text.length()-1);
  text+="]";
  
      return text;
  }
  </code></pre>
  
  <p>This is my web page code:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body onload="load();grid();marqueeload();" style="background-color:white"&gt;
  &lt;pre style="height:25px;background-color:black;"&gt;
  &lt;div id = "title" style = "text-align:center;font-size:20px;width:100%;"&gt;&lt;span&gt;REAL TIME TWITTER TRENDS&lt;/span&gt;&lt;/div&gt;
  &lt;/pre&gt;      
  &lt;div&gt;&lt;table&gt;
  &lt;tr&gt;&lt;td&gt;&lt;lable&gt;Select Date&lt;lable&gt;&lt;/td&gt;&lt;td&gt;  :  &lt;/td&gt;&lt;td&gt;&lt;input id="datepicker" type="text" /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
  &lt;/div&gt;
  &lt;div style = "width:100%"&gt;
  &lt;div id="container2" style = "width:670px;height:300px;float:left;background-color:white;border: 1px solid green;"&gt;
  &lt;div style = "text-align:center;font-size:20px;"&gt;&lt;span1&gt;CHART VIEW&lt;span1&gt;&lt;/div&gt;
  &lt;div id="container1"&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div id="container3" style = "width:670px;overflow-y:auto;height:300px;float:right;background-color:white;border: 1px solid green;"&gt; 
  &lt;div style = "text-align:center;font-size:20px;"&gt;&lt;span1&gt;GRID VIEW&lt;span1&gt;&lt;/div&gt;                                  
  &lt;div id="Grid"&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt; 
  &lt;div style = "width:100%;border: 1px solid green;height:300px;float:left;background-color:white;"&gt;
  &lt;div style = "text-align:center;font-size:20px;"&gt;&lt;span1&gt;Trending tweets&lt;span1&gt;&lt;/div&gt;
  &lt;marquee id = "marqueeid" direction="up" height="200" scrollAmount=2 scrollDelay=130 class="sidelink" onMouseDown="this.stop()" onMouseOver="this.stop()" onMouseMove="this.stop()" onMouseOut="this.start()" vspace="10" &gt;
  &lt;/marquee&gt;
  &lt;/div&gt;
  &lt;script type="text/javascript" language="javascript"&gt;
  
  function marqueeload()
  {
  
  var str;
  
  $.get("http://localhost:8080/WebApplication1/webresources/generic", function(str)
  {
  str=str.slice(12, str.length-14);
  var div=document.getElementById('marqueeid');
  div.innerHTML=str;
  });
  }
  
  $(function () {
  
               $("#datepicker").ejDatePicker({
              select: "onSelected"
              });
   $("#datepicker").ejDatePicker({ enabled: true });
      });
   function onSelected(args) {
         var str = args.value;
         var newstr = str.split("/",3);
         if(newstr[0].length == 1){
          newstr[0] = '0'+newstr[0];
         }
         if(newstr[1].length == 1){
          newstr[1] = '0'+newstr[1];
         }
         var dat = newstr[2]+'-'+newstr[0]+'-'+newstr[1];
         window.datetweet = dat;
         $("#container1").ejChart("destroy");
         grid();
         load();
  }
  function load() {
  
  var str;    
  $.get("http://localhost:8080/WebApplication1/webresources/time/"+window.datetweet,      function(str)
  {
  
  str=str.slice(12, str.length-14);
  var data=JSON.parse(str);
  
  
  
          $("#container1").ejChart(
                      {
                          primaryXAxis:
                          {
                              title: { text: 'Tagname' },
                              labelRotation: 45
                          },
  
                          primaryYAxis:
                         {
  
                             range: { min: 0, max: 1000, interval: 100 },
                             title: { text: 'Count' }
  
  
                         },
                          commonSeriesOptions: {
                              type: 'column', animation: true,
                              tooltipFormat: "#point.x# : #point.y#"
                          },
  
  
                          series: [
                              {
                                  points: data,
  
  
                              }
  
                          ],
                          load:"loadTheme",
                                                      showTooltip: true,
                          needResize:true,
  
                          size: { height: 300 },
                          legend: { visible: false, position: 'top' }
                      });
  
  });
  
      }
  
  $(document).ready(function()
  {
  
      $("#Grid").ejGrid({
      dataSource: [],
                       allowPaging: true,
                       allowSorting: true,
  
                       columns: [
                               { field: "x", headerText: "Trend Name", textAlign: ej.textAlign.Right, width: 10 },
                               { field: "y", headerText: "Count", textAlign: ej.textAlign.Right, width: 10 }
                      ]
                      });
   });
  
   function grid()
   {
      var str;
  
      var url="http://localhost:8080/WebApplication1/webresources/time/"+window.datetweet;
  
      $.get(url, function(str)
      {
          str=str.slice(12, str.length-14);
          var obj=JSON.parse(str);
          var instance = $("#Grid").ejGrid("instance");
          instance._dataManager = new ej.DataManager(obj);
          $("#Grid").ejGrid("model.dataSource", instance._dataManager);
  
      });
  
    }
  
  
  window.setInterval(function() { load(); grid(); marqueeload(); }, 10000);
  
  &lt;/script&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>