leonbloy
leonbloy

Reputation: 75986

Why https connections are so slow when debugging (stepping over) in Java?

I'm trying to debug some problems with my Java code, which establishes a http/https connection. I'm wondering why the connection gets ridiculously slow (more than one minute for downloading a small web page) when debugging, even when stepping-over the method which does the network work. And if there is some remedy.

Below I post an example (you can change https: to http: , and try debugging this from Eclipse pressing F11 - for stepping, place a breakpoint in the first main() statement, and press F6 when it pauses there.

My results (time in milliseconds) :

                        conn time   total time
http  (not stepping)        60           350
http  (stepping over)     1100          1500
https (not stepping)       570          1300
https (stepping over)    21000         83000

Edit: after disabling Show method result after a step operation option (the remedy aptly suggested by howlger's answer), the times become much more reasonable (about one-tenth for https).

http  (stepping over 2)     150           450
https (stepping over 2)    2000          7000

My scenario: Java 8 (1.8.0_121-b13) , 64 bits, Win-7, Eclipse Photon (also experienced with Oxygen).

import java.io.*;
import java.net.*;
import java.nio.charset.StandardCharsets;

public class TestConn {

    public static void downloadFromUrl(final URL url) throws IOException {
        long t0 = System.currentTimeMillis();
        URLConnection conn = url.openConnection();
        System.out.println("conn msecs: " +
              (System.currentTimeMillis() - t0) + " url=" + url);
        System.out.println("=====================================");
        try (BufferedReader in = new BufferedReader(
                new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) {
            String line;
            int cont = 0;
            while ((line = in.readLine()) != null) {
                if (cont++ < 4)
                    System.out.println(line);
            } 
            if(cont >=4) 
                System.out.printf("== total lines: %d (%d skipped)\n",cont,cont-4);
            System.out.println("==============done=======================");
        } 
    }

    public static void testConn(String urls) {
        try {
            long t0 = System.currentTimeMillis();
            downloadFromUrl(new URL(urls));
            System.out.println("Done , total time msecs: " + 
              (System.currentTimeMillis() - t0));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception {
        testConn("https://www.example.com/"); // breakpoint here, step-over with F6
        System.out.println("bye");
    }
}

Upvotes: 0

Views: 326

Answers (1)

howlger
howlger

Reputation: 34255

That's why in Window > Preferences: Java > Debug there is the preference Show method result after a step operation (if supported by the VM; maybe slow).

Since Eclipse 2018-09 (4.9) a timeout (7 seconds by defaults) can be set for that:

Upvotes: 1

Related Questions