sun.net.client.defaultReadTimeout属性问题

来源:互联网 发布:狮王手柄编程软件 编辑:程序博客网 时间:2024/06/02 23:36
同一个系统中有多处需要与外部系统通过http接口交互:
有一个处没有设置接口响应超时时间;
而另一外则使用使用System.setProperty("sun.net.client.defaultReadTimeout", 超时毫秒数字符串);来设置从服务器读取响应的超时时间;

代码一:
Java代码  收藏代码
  1. String szUrl = "http://www.ee2ee.com/";  
  2. URL url = new URL(szUrl);  
  3. HttpURLConnection urlCon = (HttpURLConnection)url.openConnection();  
  4. ...  
  5. System.out.println(urlCon.getResponseCode());//获取服务器响应  

代码二:
Java代码  收藏代码
  1. String szUrl = "http://www.ee2ee.com/";  
  2. URL url = new URL(szUrl);  
  3. HttpURLConnection urlCon = (HttpURLConnection)url.openConnection();  
  4. System.setProperty("sun.net.client.defaultReadTimeout""3000");//设置超时时间  
  5. ...  
  6. System.out.println(urlCon.getResponseCode());//获取服务器响应  


现发现系统中这两个地方的超时处理不是按代码中写的设置的超时时间去处理的,好象系统中"sun.net.client.defaultReadTimeout"属性只会是一个,不知道是什么原因?


有高手请予以回答,谢谢!


原创粉丝点击