为了账号安全,请及时绑定邮箱和手机立即绑定

为什么在 Java 中调试(跨步)时 https 连接如此缓慢?

为什么在 Java 中调试(跨步)时 https 连接如此缓慢?

狐的传说 2022-01-12 14:22:09
我正在尝试调试我的 Java 代码的一些问题,该代码建立了 http/https 连接。我想知道为什么在调试时连接会变得非常慢(下载一个小网页超过一分钟),即使是在跨过网络工作的方法时也是如此。如果有一些补救措施。下面我发布了一个示例(您可以更改https:为http:,并尝试从 Eclipse 按下调试它F11- 对于单步执行,在第一个main()语句中放置一个断点,并F6在它在那里暂停时按下。我的结果(以毫秒为单位的时间):                        conn time   total timehttp  (not stepping)        60           350http  (stepping over)     1100          1500https (not stepping)       570          1300https (stepping over)    21000         83000编辑:停用后,Show method result after a step operation选项(通过howlger的回答恰如其分地提出补救措施),时代变多更加合理(约十分之一用于HTTPS)。http  (stepping over 2)     150           450https (stepping over 2)    2000          7000我的场景:Java 8 (1.8.0_121-b13),64 位,Win-7,Eclipse Photon(也体验过 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=======================");        }     }
查看完整描述

1 回答

?
海绵宝宝撒

TA贡献1809条经验 获得超8个赞

这就是为什么在Window > Preferences: Java > Debug 中有首选项Show method result after a step operation (如果 VM 支持;可能很慢)

查看完整回答
反对 回复 2022-01-12
  • 1 回答
  • 0 关注
  • 283 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号