【问题标题】:setConnectTimeout causes hang?setConnectTimeout 导致挂起?
【发布时间】:2013-03-24 12:46:03
【问题描述】:

嗨,我正在尝试测试代理,但如果我将 setConnectTimeout 设置为超过 1500,它会导致程序挂起,它只会死掉,什么都不会打印出来我的处理器和内存没有做很多事情,它只是死了有没有人知道解决方案的代码是
HttpURLConnection inSite = (HttpURLConnection) site.openConnection(proxy);
inSite.setConnectTimeout(2000); //如果设置在1500以下就可以了

这是一个真正的问题,因为大多数代理在这段时间内响应太慢,谢谢

【问题讨论】:

    标签: time out


    【解决方案1】:

    私有最终 ScheduledExecutorService 调度程序 = Executors.newScheduledThreadPool(1);

    public void sixtymin() {
    
        final Runnable logger= new Runnable() {//instansiation
    
            @Override
            public void run() {
                System.out.println(System.currentTimeMillis());//code to execute
            }
                //You application logic as shown in the question
            };
        final ScheduledFuture<?> loggerHandle =
            scheduler.scheduleAtFixedRate(logger, 0, 5, SECONDS );//action,delay before first run,delay between,unit
    

    这是上述代码每 5 秒打印一次的解决方案,所以我用它来终止进程超时

    【讨论】:

      猜你喜欢
      • 2014-05-11
      • 2014-08-14
      • 1970-01-01
      • 1970-01-01
      • 2015-01-27
      • 2014-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多