Spring SimpleJdbcTemplate:java.lang.OutOfMemoryError:超出GC开销限制

Spring SimpleJdbcTemplate:java.lang.OutOfMemoryError:超出GC开销限制,java,oracle,spring,jdbc,garbage-collection,Java,Oracle,Spring,Jdbc,Garbage Collection,我正在深入研究Spring,我一直在使用SimpleJdbcTemplate来帮助减少需要编写的代码量,但现在我遇到了一个问题,抛出了异常“java.lang.OutOfMemoryError:超出GC开销限制”。我一直在使用eBay的web服务从eBay中提取类别,并通过调用jdbTemplate.update(见下面的代码)插入每个类别(我想大约有10000条记录) 类别服务: // If the category already exist (i.e. an error is throuw

我正在深入研究Spring,我一直在使用SimpleJdbcTemplate来帮助减少需要编写的代码量,但现在我遇到了一个问题,抛出了异常“java.lang.OutOfMemoryError:超出GC开销限制”。我一直在使用eBay的web服务从eBay中提取类别,并通过调用jdbTemplate.update(见下面的代码)插入每个类别(我想大约有10000条记录)

类别服务:

// If the category already exist (i.e. an error is throuwn as the version must be unique) than do now bother sotring the categories
for(CategoryType ct : categories)
{
    try
    {
        // TODO: Determine why a child ategory can be tied to multiple parents, for now just use the first category in the array
        categoryDao.SaveCategory(ct.getCategoryID(), ct.getCategoryName(), ct.getCategoryParentID()[0]);
    }
    catch(DuplicateKeyException e)
    {
        // No problem here, the version description is the same... just continue as if nothing happened
    }
}
CategoryDaoImpl:(CategoryDao接口的实现)

环境:

  • Spring框架3.0.2
  • Oracle数据库XE(我想是11g!)(使用ojdbc6.jar)
  • JDK(jdk1.6.0_26)
我曾想过在SimpleJdbcTemplate上使用batchUpdate方法,但我不确定这里是否存在潜在问题


任何帮助都将不胜感激

立即停止将所有类别加载到内存中。在加载每个类别时对其进行处理。它将至少快一个数量级,并且不会引起OOMEs。

立即停止将所有类别加载到内存中。在加载每个类别时对其进行处理。这将至少快一个数量级,并且不会引起OOMEs。

检查此项我想batchUpdate将是一个好选项检查此项我想batchUpdate将是一个好选项嗨,Ryan,谢谢您的回复。你能不能用一个代码示例进一步说明,因为我不完全理解你的意思。Ebay一次返回10000多条记录,这些记录将存在于api调用后的内存中。@JLove:您说这是一个web服务,这意味着这是某种HTTP请求。HTTP总是(几乎)流。你不必等到整个反应回来。一旦开始接收它,就可以开始解析它。这样做需要做更多的工作,但它绝对会给您带来巨大的性能提升。我将尝试收集一些示例代码,但它只是非常一般的。嗨,Ryan,谢谢你的回复。你能不能用一个代码示例进一步说明,因为我不完全理解你的意思。Ebay一次返回10000多条记录,这些记录将存在于api调用后的内存中。@JLove:您说这是一个web服务,这意味着这是某种HTTP请求。HTTP总是(几乎)流。你不必等到整个反应回来。一旦开始接收它,就可以开始解析它。这样做需要做更多的工作,但它绝对会给您带来巨大的性能提升。我将尝试收集一些示例代码,但它只是非常一般的。
@Override
public int SaveCategory(String ebayCategoryId, String ebayCategoryName, String ebayParentCategoryId) 
{
    // Firstly grab the next value in the categoru sequence
    int internalCategoryId = jdbcTemplate.queryForInt(categorySequenceStatement);

    // Insert the new category
    jdbcTemplate.update(insertCategoryStatement, new Object[] {internalCategoryId, ebayCategoryId, ebayCategoryName, ebayParentCategoryId});

    return internalCategoryId;
}