details: https://code.openbravo.com/erp/devel/pi/rev/8466c9b3c506
changeset: 16735:8466c9b3c506
user: Asier Lostalé <asier.lostale <at> openbravo.com>
date: Fri Jun 01 08:53:46 2012 +0200
summary: fixed bug 20658: Heap space problem when exporting big csv files
In fetch for csv exportation, changed evict with clear. Evict removes current
record from memory, but it doesn't remove its references, this causes unnecesary
memory consumption.
diffstat:
modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
| 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diffs (33 lines):
diff -r b5f0e719c9c2 -r 8466c9b3c506
modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
---
a/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
Mon Jun 04 11:01:30 2012 +0200
+++
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
Fri Jun 01 08:53:46 2012 +0200
@@ -178,6 +178,7 @@
}
public void fetch(Map<String, String> parameters, QueryResultWriter writer) {
+ long t = System.currentTimeMillis();
final String entityName = parameters.get(JsonConstants.ENTITYNAME);
final DataEntityQueryService queryService =
createSetQueryService(parameters);
queryService.setEntityName(entityName);
@@ -187,13 +188,20 @@
toJsonConverter.setAdditionalProperties(JsonUtils.getAdditionalProperties(parameters));
final ScrollableResults scrollableResults = queryService.scroll();
+ int i = 0;
while (scrollableResults.next()) {
final Object result = scrollableResults.get()[0];
final JSONObject json = toJsonConverter.toJsonObject((BaseOBObject)
result,
DataResolvingMode.FULL);
writer.write(json);
- OBDal.getInstance().getSession().evict(result);
+ i++;
+ // Clear session every 1000 records to prevent huge memory consumption
in case of big loops
+ if (i % 1000 == 0) {
+ OBDal.getInstance().getSession().clear();
+ log.debug("clearing in record " + i + " elapsed time " +
(System.currentTimeMillis() - t));
+ }
}
+ log.debug("Fetch took " + (System.currentTimeMillis() - t) + " ms");
}
private DataEntityQueryService createSetQueryService(Map<String, String>
parameters) {
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits