我OutOfMemoryError
在用 400k 记录查询 MongoDb 时得到了。我有一个包含大约 40 万条记录的用户集合。当我尝试检索所有用户(以将其转储到弹性搜索中)时, OutOfMemoryError
出现错误。
我已经浏览了这个链接并在 application.config 中添加了jvm.memory=-Xms64m -Xmx1024m,但仍然是同样的异常。
这是我的堆栈跟踪 -
OutOfMemoryError occured : Java heap space
play.exceptions.JavaExecutionException: Java heap space
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:237)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.OutOfMemoryError: Java heap space
at java.util.HashMap.<init>(HashMap.java:209)
at java.util.LinkedHashMap.<init>(LinkedHashMap.java:181)
at org.bson.BasicBSONObject.<init>(BasicBSONObject.java:45)
at com.mongodb.BasicDBObject.<init>(BasicDBObject.java:42)
at com.mongodb.DefaultDBCallback._create(DefaultDBCallback.java:124)
at com.mongodb.DefaultDBCallback.create(DefaultDBCallback.java:87)
at org.bson.BasicBSONCallback.objectStart(BasicBSONCallback.java:68)
at com.mongodb.DefaultDBCallback.objectStart(DefaultDBCallback.java:63)
at org.bson.BasicBSONCallback.objectStart(BasicBSONCallback.java:63)
at org.bson.BasicBSONDecoder.decodeElement(BasicBSONDecoder.java:206)
at org.bson.BasicBSONDecoder.decodeElement(BasicBSONDecoder.java:197)
at org.bson.BasicBSONDecoder.decodeElement(BasicBSONDecoder.java:207)
at org.bson.BasicBSONDecoder._decode(BasicBSONDecoder.java:80)
at org.bson.BasicBSONDecoder.decode(BasicBSONDecoder.java:58)
at com.mongodb.DefaultDBDecoder.decode(DefaultDBDecoder.java:56)
at com.mongodb.Response.<init>(Response.java:66)
at com.mongodb.DBPort.go(DBPort.java:128)
at com.mongodb.DBPort.call(DBPort.java:79)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:218)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:189)
at com.mongodb.DBApiLayer$Result._advance(DBApiLayer.java:452)
at com.mongodb.DBApiLayer$Result.hasNext(DBApiLayer.java:418)
at com.mongodb.DBCursor._hasNext(DBCursor.java:503)
at com.mongodb.DBCursor.hasNext(DBCursor.java:523)
at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1520)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1332)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1318)
at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:504)
at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:499)
at com.salambc.service.ProfileService.getUsers(ProfileService.java:895)
at controllers.Admin.index(Admin.java:56)