Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7617427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:08:53+00:00 2026-05-31T03:08:53+00:00

I am trying to call a web service, the response contains a big string,

  • 0

I am trying to call a web service, the response contains a big string, getting out of memory issue the code is

 URL u = new URL(SharedVariables.server);
           URLConnection uc = u.openConnection();
           HttpURLConnection connection = (HttpURLConnection) uc;
           connection.setConnectTimeout(SharedVariables.connectionTimedOutValue);
           connection.setDoOutput(true);
           connection.setDoInput(true);
           connection.setRequestProperty("SOAPAction", SOAP_ACTION);
           connection.setRequestMethod("POST");
           connection.setRequestProperty("Content-type", "text/xml; charset=utf-8");

           String xmldata = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
                            "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> "+ 
                            "<soap:Body>"+
                            "<GetCaseCriminalTicketLinks xmlns=\"http://tempuri.org/\">"+   
                            Req.getRequestXml()+                            
                            "</GetCaseCriminalTicketLinks>"+
                            "</soap:Body>"+
                            "</soap:Envelope>";        

           OutputStream out = connection.getOutputStream();
                Writer wout = new OutputStreamWriter(out);
                wout.write(xmldata);
                wout.flush();                   
                out.flush();                    


              BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()),8 * 1024);

              String result;    

              while ((result=rd.readLine()) != null) {


              int length = result.length();               
               String temp = result.substring(316, (length - 100));           

               JSONObject tempJson = new JSONObject(temp);}

The log is

Caused by: java.lang.OutOfMemoryError
at java.lang.String.<init>(String.java:513)
at java.lang.AbstractStringBuilder.toString(AbstractStringBuilder.java:650)
at java.lang.StringBuilder.toString(StringBuilder.java:664)
at java.io.BufferedReader.readLine(BufferedReader.java:398)

this line is causing

while ((result=rd.readLine()) != null) 

Any suggestions ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:08:55+00:00Added an answer on May 31, 2026 at 3:08 am

    For all the variables available in the while ((result=rd.readLine()) != null) loop, the memory will be created on the Heap, as you mentioned you are trying to stream aroung 1 MB data, loop will exceute long time so obivously the heap has become overloaded to store the data.

    My suggestions:

    1. Try to stream minimum amount of data and check
    2. Avoid having Instantiation of objects inside loop, use references instead.
    3. Find a way to increase the JVM memory size

    Links to consider are:

    Increase heap size in java

    JVM-Java increase heap size

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying out BizTalk with a web service call The request/response is working fine on
I'm trying to work out what a BizTalk call to a web service is
I'm trying to call a web service in my back end java code when
I'm trying to call a web service from Excel 2003 module. The way i've
I'm trying to call a web service in an Excel Macro: Set objHTTP =
I am trying to call a web service from asp.net 3.5 application. I have
I am trying to call a web service (using nusoap ), which work well
We have a customer that is trying to call our web service written in
I using VB.NET 2.0. I am trying to call a web service. This web
I'm running into this problem when trying to call a SOAP Web Service from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.