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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:51:44+00:00 2026-06-05T01:51:44+00:00

I want to know what has been done when URL.openconnection(). i have done some

  • 0

I want to know what has been done when URL.openconnection().
i have done some test like this:

public static void main(String[] args) {
    //    testConnection("http://www.google.com");
    testConnection("http://219.09.34.23.1");
}

private static void testConnection(final String _url) {
    new Thread(new Runnable() {
        String strurl = _url;
        long starttime = 0;
        long endtime = 0;

        public void run() {
            try {
                System.out.println("open:" + strurl);

                starttime = System.currentTimeMillis();
                System.out.println("starttime:" + starttime);

                URL url = new URL(strurl);
                HttpURLConnection conn = (HttpURLConnection) url
                        .openConnection();

                endtime = System.currentTimeMillis();
                System.out.println("openConnection endtime:" + endtime);
                System.out
                        .println("spend:" + (endtime - starttime) + " ms");

                conn.connect();
                endtime = System.currentTimeMillis();
                System.out.println("connect endtime2:" + endtime);
                System.out
                        .println("spend:" + (endtime - starttime) + " ms");

                conn.getResponseCode();
                endtime = System.currentTimeMillis();
                System.out.println("endtime3:" + endtime);
                System.out
                        .println("spend:" + (endtime - starttime) + " ms");
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();

                endtime = System.currentTimeMillis();
                System.out.println("MalformedURLException endtime:"
                        + endtime);
                System.out
                        .println("spend:" + (endtime - starttime) + " ms");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();

                endtime = System.currentTimeMillis();
                System.out.println(" IOException endtime:" + endtime);
                System.out
                        .println("spend:" + (endtime - starttime) + " ms");
            }

        }
    }).start();
}

when i run testConnection(“http://www.google.com”), all things are ok.
when i run testConnection(“http://219.09.34.23.1”), “219.09.34.23.1” is a random ip maybe not exist i wrote, it print this:

open:http://219.09.34.23.1
starttime:1338978920350
openconnection endtime:1338978920355
spend:5 ms

    java.net.UnknownHostException: 219.09.34.23.1  
    at java.net.PlainSocketImpl.connect(Unknown Source)  
    at java.net.SocksSocketImpl.connect(Unknown Source)  
    at java.net.Socket.connect(Unknown Source)  
    at java.net.Socket.connect(Unknown Source)  
    at sun.net.NetworkClient.doConnect(Unknown Source)  
    at sun.net.www.http.HttpClient.openServer(Unknown Source)  
    at sun.net.www.http.HttpClient.openServer(Unknown Source)  
    at sun.net.www.http.HttpClient.<init>(Unknown Source)  
    at sun.net.www.http.HttpClient.New(Unknown Source)  
    at sun.net.www.http.HttpClient.New(Unknown Source)  
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)  
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)  
    at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)  
    at Main$1.run(Main.java:37)  
    at java.lang.Thread.run(Unknown Source)

IOException endtime:1338978920393
spend:43 ms

it means it spent 5ms to run openconnection, and spent 43ms to find it is a unknownhost, my problem is, what has been done when URL.openconnection() as “219.09.34.23.1” is unknownhost?
Thanks for any help!

  • 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-06-05T01:51:46+00:00Added an answer on June 5, 2026 at 1:51 am

    If you read the javadocs for URL.openConnection(), you’ll find:

    Returns a URLConnection instance that represents a connection to the
    remote object referred to by the URL.

    A new instance of URLConnection is created every time when invoking
    the URLStreamHandler.openConnection(URL) method of the protocol
    handler for this URL.

    It should be noted that a URLConnection instance does not establish
    the actual network connection on creation. This will happen only when
    calling URLConnection.connect().

    Update

    The IP you used in your “random ip” is not valid; it should consist of 4 octets, not 5. The 43ms is probably for: (1) doing a DNS lookup on the non-IP ip (2) printing the stack trace.

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

Sidebar

Related Questions

I know this question has been asked quite a few times, however, I have
I know this subject has been done already over and over. but... i must
I know this has been done before, but I am running into an issue
I want to know if Netbeans has some option or setting that will allow
I have never done this before This is my current .htaccess file, I want
I know this has been covered so much but I'm a little out of
I'm sure this has already been done, but Google isn't helping me - I'm
I know that the topic of C++ delegates has been done to death, and
I know this question has been asked before but I still haven't seen a
I know that there has been one question about this but it is not

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.