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 6797479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:36:52+00:00 2026-05-26T18:36:52+00:00

I have a Java program that uses OAuth for communication with a server to

  • 0

I have a Java program that uses OAuth for communication with a server to retrieve XML data.

It makes use of the Signpost OAuth library to connect with the source, and uses a standard way of reading the InputStream to access the XML that is returned.

Of late, I’ve noticed the slow time it’s taken to retrieve the information and tests have revealed that some requests can take anywhere from 2000 ms up to 10000 ms (if it matters, the source server is in Europe, I am in Australia).

I added a timestamp after the OAuth communication (request.connect()) and again after the reading of the InputStream and here’s the output:

Request #1: Communication: [6351ms] Data process: [403ms] Total: [6754ms]
Request #2: Communication: [1ms] Data process: [3121ms] Total: [3122ms]
Request #3: Communication: [1ms] Data process: [1297ms] Total: [1298ms]
Request #4: Communication: [0ms] Data process: [539ms] Total: [539ms]
  • Request #4 is actually Request #2 being run a 2nd time. All requests are made in one run of the program (there’s no stopping and starting).

My question: is the InputStream returned to the HttpURLConnection object as part of the connect() method, or is it streamed back as I read from it (as the name suggests) and part of the actual connection process?

Secondary question: With the timing above, is the slow time most likely to be a problem with the server or my method of reading the InputStream?

For reference, here is the code in question:

long startTime = System.currentTimeMillis();
URL url = new URL(urlString);
HttpURLConnection request = (HttpURLConnection) url.openConnection();
consumer.sign(request);
request.connect();

long connectionTime = System.currentTimeMillis();

InputStream is = request.getInputStream();
if (is != null) {
    final BufferedReader bufferedreader = new BufferedReader(
              new InputStreamReader(is, "UTF-8"));
    final StringBuffer s2 = new StringBuffer();
    String line;
    line = bufferedreader.readLine();
    if (line != null) {
        s2.append(line);
        while ((line = bufferedreader.readLine()) != null) {
            s2.append('\n');
            s2.append(line);
        }
    }
    bufferedreader.close();
    rv = s2.toString();
}
long finishTime = System.currentTimeMillis();
long timeTaken = finishTime - startTime;
long totalConnectionTime = connectionTime - startTime;
long processDataTime = finishTime - connectionTime;
String info = "Communication: [" + totalConnectionTime + 
                    "ms] Data process: [" + processDataTime + 
                    "ms] Total: [" + timeTaken + "ms]";

Thanks in advance.

  • 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-26T18:36:52+00:00Added an answer on May 26, 2026 at 6:36 pm

    Based on the information provided, here are few observations and suggestions.

    1. To answer your question, the data is streamed back as you read from it. And then you have buffered layers on the top of it. The whole data is not returned and its streamed. I hope I read your question correctly.
    2. The secondary question: The time taken could in both the places viz. the server and in your code as well. Since you are not doing any other processing in your code other than reading the data (except Bufferedreader.close() and s2.toString();) the delay appears to be in server BUT just for being sure, if possible, hit the URL using any browser and see the time taken to fetch the request. (from the code I see that you are just fetching the data from URL and hence should be easy to access the same using browser)
    3. You also have mentioned that you are retrieving XML from the server. I would recommend to use some standard xml parsers (SAX,xstrem etc) which are optimized (hence better performance) for reading xml data from an InputStream.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

actually i have a java program that reads the data from a specific XML
I have a java client program that uses mdns with service discovery to find
Let's say I have a java program that makes an HTTP request on a
I have a java program that uses a weak hashmap for caching some things,
I have a Java program that uses reflection to find and invoke the main(String[]
I have a Java program that outputs some text into console. It uses print
I have a java program using an external library. The main program uses log4j
I have a small Java program that uses ImageIcons on JLabels to display pictures.
I am developing a program in Java that I will use for registering data.
I'm have a java program that uses Apache httpclient api. This is used to

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.