JavaFX - 从JSON数据在HSQLDB中存储数据时的OME

时间:2014-06-30 15:23:57

标签: java performance javafx-2 hsqldb

我使用HSQLDB在我的应用程序中存储数据。我逐个拨打15个Web服务电话。并将数据存储在DB中。它可以处理最大量的数据。我得到了大数据的OME(内存不足错误)。我的意思是,假设我有20k的Web服务方法记录。所以我们在将数据存储到数据库时获取OME。我尝试使用分析器功能,但我无法找到哪个对象消耗了更多的堆内存。所以我来到这里。我需要有人帮忙解决这个问题。

Code

 try {
            JSONObject jSONObject = getJSONData(clientId, ApplicationConstants.REST_METHOD_GET_ALL_CATEGORIES_LIST_BY_CLIENT_ID);
            if (jSONObject != null) {
                JSONArray jSONArray = jSONObject.getJSONArray(ApplicationConstants.JSON_OBJECT_RESPONSE);
                Integer length = jSONArray.length();
                if (length == 0) {
                    if (_logger.isInfoEnabled()) {
                        _logger.info("Categories not found for client {}", clientId);
                    }
                } else {
                    if (_logger.isInfoEnabled()) {
                        _logger.info("{} Categories found for client {}", length, clientId);
                    }

                    SyncDao synDao = (SyncDao) getDAO(ApplicationConstants.REST_SYNC_DAO);

                    for (int i = 0; i < length; i++) {
                        JSONObject jSONObj = jSONArray.getJSONObject(i);
                        ProjectMenu projectMenu = new ProjectMenu();
                        projectMenu.setClientId(clientId);
                        projectMenu.setCategory(ApplicationConstants.PROJECT_MENU_CATEGORY_SUB_MENU);
                        projectMenu.setCategoryType(ApplicationConstants.CATEGORY_TYPE_CATEGORY);
                        projectMenu.setCreatedDate(jSONObj.getString(ApplicationConstants.REST_CATEGORY_CREATED_DATE));
                        projectMenu.setElementId(jSONObj.getString(ApplicationConstants.REST_CATEGORY_ID));
                        projectMenu.setIsLeaf(Boolean.FALSE);
                        projectMenu.setLabel(jSONObj.getString(ApplicationConstants.REST_CATEGORY_NUMBER));
                        projectMenu.setLevel(new Integer(4));
                        projectMenu.setSortOrder(jSONObj.getInt(ApplicationConstants.REST_CATEGORY_SORT_ORDER));
                        // Getting parent menu details
                        ProjectMenu parentProjectMenu = synDao.getProjectMenu(clientId, 
                                jSONObj.getString(ApplicationConstants.REST_CATEGORY_PROJECT_COMPONENT_ID), ApplicationConstants.CATEGORY_TYPE_COMPONENT);
                        if (parentProjectMenu != null) {
                            if (ApplicationConstants.REST_NO_COMPONENT_LABEL.equalsIgnoreCase(parentProjectMenu.getLabel())) {
                                projectMenu.setParentMenuId(parentProjectMenu.getParentMenuId());
                            } else {
                                projectMenu.setParentMenuId(parentProjectMenu.getId());
                            }
                            projectMenu.setProjectId(parentProjectMenu.getProjectId());
                        }

                        if (_logger.isDebugEnabled()) {
                            _logger.debug("Persisting Category: {}", projectMenu.toString());
                        }
                        synDao.persist(projectMenu);
                    }
                }
            }
        } catch (JSONException jsonex) {
            if (_logger.isErrorEnabled()) {
                _logger.error("Exception while synchronizing Categories.", jsonex);
            }
        }

1 个答案:

答案 0 :(得分:0)

当数据库中的数据量变大时,使用MEMORY表通常会导致OOM错误。

将包含大量数据的表转换为CACHED表,不再有OOM错误。

SET TABLE t TYPE CACHED