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

发布于 2024-11-26 13:35:44 字数 1598 浏览 1 评论 0原文

我正在尝试使用 Spring,并且一直在使用 SimpleJdbcTemplate 来帮助减少需要编写的代码量,但现在遇到一个问题,抛出异常“java.lang.OutOfMemoryError:超出 GC 开销限制” 。我一直使用 eBay 的 Web 服务将类别从 eBay 中提取出来,并且使用调用 jdbTemplate.update(参见下面的代码)插入每个类别(我认为大约 10,000 条记录)

CategoryService:

// 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 接口)

@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;
}

环境:

  • Spring Framework 3.0.2
  • Oracle Database XE(我认为是 11g!)(使用 ojdbc6.jar)
  • JDK (jdk1.6.0_26)

我曾在 SimpleJdbcTemplate 上使用过 batchUpdate 方法,但我不确定这里是否存在潜在问题。

任何帮助将不胜感激!

I'm dipping my toe into Spring and I've been using the SimpleJdbcTemplate to help reduce the amount of code I need to write but I now have an issue where the exception "java.lang.OutOfMemoryError: GC overhead limit exceeded" is thrown. I've been pulling the categories out of eBay using their web services and I've been inserting each category (about 10'000 records I think) using a call jdbTemplate.update (see code below)

CategoryService:

// 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: (an implementation of the CategoryDao Interface)

@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;
}

Environment:

  • Spring Framework 3.0.2
  • Oracle Database XE (11g I think!) (using ojdbc6.jar)
  • JDK (jdk1.6.0_26)

I had though of using the batchUpdate method on SimpleJdbcTemplate but I'm unsure of whether there is an underlying issue here.

Any help would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灯角 2024-12-03 13:35:44

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

Stop loading all the categories into memory at once. Process each category as it's loaded. It will be at least an order of magnitude faster and won't cause OOMEs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文