2013-04-03 154 views
0

嗨即時嘗試測試代理,但如果我設置setConnectTimeout超過1500它會導致程序掛起它只是沒有得到打印我的處理器和memery arint做很多它只是死有沒有人知道這個代碼的解決方案是
HttpURLConnection inSite =(HttpURLConnection)site.openConnection(proxy);
inSite.setConnectTimeout(2000); //如果設置爲低於1500其細setConnectTimeout導致掛起?

這是一個真正的概率,因爲大多數代理是太慢了respon在這個時候的感謝

回答

0

私人最終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秒,所以我用它來殺死過程ofter超時