Exception in thread "http-apr-8080-exec-11"
<p>My java application was running fine, but now only some functionality of it throws this error</p>

<pre><code>Exception in thread "http-apr-8080-exec-11" java.lang.OutOfMemoryError: Java heap space
 at java.util.Arrays.copyOf(Arrays.java:2367)
 at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:130)
 at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:114)
 at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:587)
 at java.lang.StringBuilder.append(StringBuilder.java:214)
 at org.apache.struts2.json.JSONWriter.add(JSONWriter.java:575)
</code></pre>

<p>functionalities are add campaign and delete campaign. When i try to add a campaign or delete a campaign this error is thrown.
Theres option of adding keywords in each campaign, that is running fine. and also other parts of application is running fine.</p>

<p>code snippet of the delete campaign service </p>

<pre><code>   public String deleteSerpsCampaign() {
    objRequest = ServletActionContext.getRequest();

    //initializing http session object
    objSession = objRequest.getSession();

    //checking for 'customerID' attribute in session
    if (objSession.getAttribute("customerID") != null) {
        Integer campaignId = 0;
        campaignId = Integer.parseInt(jString);
        System.out.println("Site id is:::" + campaignId);

        //reading the 'customerID' from session and type casting it to integer
        Integer customerID = (Integer) objSession.getAttribute("customerID");

        //now invoking the deleteCampaign() method of CampaignsServiceImpl
        String campaignName = objCampaignsService.deleteCampaign(campaignId, customerID);
        message = "'" + campaignName + "' - Campaign has been Deleted";
        objSession.setAttribute("message", message);
        return SUCCESS;
    }

    //if session attribute 'customerID' is null then return result parameter as 'LOGIN'
    //this result parameter is mapped in 'struts.xml'
    return LOGIN;
}
</code></pre>

<p>deleteCampaign method</p>

<pre><code>   public String deleteCampaign(Integer campaignId, Integer customerID) {
    int delCount = 0;
    Campaigns objcamp = (Campaigns) getSession().get(Campaigns.class, campaignId);
    try {
        Collection objserpkeywords = objcamp.getSerpkeywordsCollection();
        Iterator itr = objserpkeywords.iterator();
        while (itr.hasNext()) {
            Serpkeywords objserpkeys = (Serpkeywords) itr.next();
            if (objserpkeys.getVisibility() == 1) {
                delCount++;
                objserpkeys.setVisibility(0);
                getSession().update(objserpkeys);
            }
        }
        Collection objseokeywords = objcamp.getSeokeyworddetailsCollection();
        Iterator ittr = objseokeywords.iterator();
        while (ittr.hasNext()) {
            Seokeyworddetails objseokeys = (Seokeyworddetails) itr.next();
            if (objseokeys.getVisibility() == 1) {
                objseokeys.setVisibility(0);
                getSession().update(objseokeys);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        String sQuery = "update campaigns set visibility=0 where CampaignID=:campaignId";
        SQLQuery objQuery = getSession().createSQLQuery(sQuery);
        objQuery.setParameter("campaignId", campaignId);
        objQuery.executeUpdate();
    } catch (DataAccessResourceFailureException | IllegalStateException | HibernateException ex) {
        l.error(ex + "  " + ex.getMessage());
    }
    Customers objCustomers = (Customers) getSession().get(Customers.class, customerID);
    try {
        objCustomers.setActiveSerpCampaignsCount(objCustomers.getActiveSerpCampaignsCount() - 1);
        objCustomers.setActiveKeywordCount(objCustomers.getActiveKeywordCount() - delCount);
        getSession().update(objCustomers);
    } catch (DataAccessResourceFailureException | IllegalStateException | HibernateException ex) {
        l.error(ex + "  " + ex.getMessage());
    }
    return objcamp.getCampaign();
}
</code></pre>