Spring SimpleJdbcTemplate:java.lang.OutOfMemoryError:超出GC开销限制
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
停止一次将所有类别加载到内存中。在加载每个类别时对其进行处理。它至少会快一个数量级,并且不会导致 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.