0

I am calling an Autodesk API GET {urn}/metadata/{guid}/properties
this API returns {"result":"success"} as JSON String for the first time.

If I call the same API repeatedly using a while loop it returns the properties of a flat list of objects from an object tree of 64MB of data.

To verify the data I received from API, below code is what I have written

boolean hasResult = false;
boolean hasData = false;
String result
do {
  result = api call
  JSONObject jo = new JSONObject(result);
  hasResult = jo.has("result");
  hasData = jo.has("data");
  if (hasData) {
    break;
  }
} while (hasResult);

This process leads to running out of memory java heap space issue.

  • You have infinite loop. In case jo has "result" but does not have "data". – Milkmaid Jun 20 '22 at 06:44
  • How often does it loops through? I assume you are running into an infinite loop problem. It seems like `result` is always true so the `while` loop is never ending. Further `hasData` seems to be always false (based on your json response) and therefore never hitting the `break` statement. – Daniel Rafael Wosch Jun 20 '22 at 06:47
  • @DanielWosch Maximum loop may run 2 to 3 times, after that I will definitely because it is working for small size response data is working fine – Pradeep Virtuele Jun 20 '22 at 07:02
  • @PradeepVirtuele And when does it run OOM? The **first** call to the API returns `{"result":"success"}` and all following calls return *the properties of a flat list of objects from an object tree of 64MB of data* ? Could you provide the other object structure? – Daniel Rafael Wosch Jun 20 '22 at 07:06
  • when does it run OOM? this is what I don't know but I am sure this not going for an infinite loop. object structure like this { "data": { "type": "properties", "collection": [{}, {}] } } the collection JSONArray can contain 40 thousand JSONObjects and more – Pradeep Virtuele Jun 20 '22 at 08:26
  • @DanielWosch For OOM My guesses are 1. The problem is in receiving 60MB to String 2. Converting 60 MB JSON String to JSON i.e JSONObject jo = new JSONObject(result); – Pradeep Virtuele Jun 21 '22 at 05:20
  • Does the stack trace no print out the line where the OOM occurs? – Daniel Rafael Wosch Jun 21 '22 at 05:45
  • I would guess this may be just because the properties data is huge. When the http response tries to fetch the data, it is time out. give it a try with RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(30 * 1000).build(); HttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build(); – Xiaodong Liang Jul 01 '22 at 01:58

0 Answers0