MDA/MDD/TDD/DDD/DDDDDDD
posts - 536, comments - 111, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

weblogic上HttpURLConnection的超时

Posted on 2010-04-14 16:59 leekiang 阅读(4151) 评论(0)  编辑  收藏 所属分类: 应用服务器
System.setProperty("sun.net.client.defaultConnectTimeout", "500");
System.setProperty("sun.net.client.defaultReadTimeout", "500");
在jdk1.4.2_05下测http,上面的代码是生效的,https没有试。
好像jdk1.4.2.12解决了https的问题,见jdk1.4的bug清单。
HttpURLConnection的实现类正常情况下是sun.net.www.protocol.http.HttpURLConnection
而weblogic8下是weblogic.net.http.SOAPHttpURLConnection。
SOAPHttpURLConnection是weblogic.net.http.HttpURLConnection的子类
System.setProperty("weblogic.client.SocketConnectTimeoutInSecs", "500");在sp4不管用
-Dweblogic.client.SocketConnectTimeoutInSecs=500也不管用。

在http://forums.oracle.com/forums/thread.jspa?threadID=766767里有人说
Well, it depends on the OS and JVM used. If Weblogic is using Native library (socket Muxer) for remote communication then socketconnectTimeout only helps when thread is stuck on "Socket.connect() method, but it would never timeout the socket if it is stuck on "Socket.read()" because the Control does not return to JVM till OS level TCP/IP connection returns.
To resolve this issue, try to timeout TCP connections at OS level using OS parameters. Hopefully BEA would come with some resolution of this issue in future release

应该使用"weblogic.http.client.defaultConnectTimeout"属性
在weblogic9的weblogic.net.http.HttpURLConnection类里找到如下的代码
defaultConnectTimeout = Integer.getInteger("weblogic.http.client.defaultConnectTimeout", -1).intValue();
而在weblogic8.1 sp4的该类里没找到,或许sp5就有了(见http://download.oracle.com/docs/cd/E13222_01/wls/docs81///javadocs/weblogic/net/http/HttpURLConnection.html)

  现在的问题是,对于这种问题可不可以通过超时设定来释放线程。weblogic中,RJVM(即server之间,可能是admin-to- managed,也可能是managed-to-managed)之间,连接的协议有两类五种,两类是http、t3,五种是http、https、 t3、t3s、local。超时设定时协议层面的东西,所以我们这里只讨论http和t3。

       对于t3,从上面的trace可以看到,连接的创建从ServerURL.findOrCreateRJVM()开始,这个方法有多种实现,不同的实现使用不同的timeout,客户端程序可以通过向environment中set一个叫做weblogic.jndi.requestTimeout的变量,如果不做设定,则使用系统默认的DEFAULT_CONNECTION_TIMEOUT,这是个静态值(0)。而在上面的stacktrace中,我们可以看到,environment是在RemoteChannelServiceImpl中定义的,这个environment对于客户而言是不可配置的,而weblogic自己的这个env中是不设定requesttimeotu的,也就是,无论哪种方式,connectionTimeout/readTimeout对于t3,都是不可配置的,而且默认是没有超时的。

        而对于http,HTTPClientJVMConnection在创建HttpURLConnection的时候,会读取系统环境变量中的如下两个变量,
[b]weblogic.http.client.defaultReadTimeout[/b]
[b]weblogic.http.client.defaultConnectTimeout[/b]
        如果没有设定,这两个变量的默认值均为-1,即不做timeout。如果我们作了设定,这两个值即读超时、连接超时都会生效。这两个值可以用于解决上述的问题。
        weblogic.http.client.defaultReadTimeout
weblogic.http.client.defaultConnectTimeout

哪里可以设置呢?
举例:
Windows平台:
set JAVA_OPTIONS=-Dweblogic.http.client.defaultReadTimeout=30 -Dweblogic.http.client.defaultConnectTimeout=30 %JAVA_OPTIONS%
UNIX/Linux平台:
JAVA_OPTIONS="-Dweblogic.http.client.defaultReadTimeout=30 -Dweblogic.http.client.defaultConnectTimeout=30 $JAVA_OPTIONS"
export JAVA_OPTIONS


只有注册用户登录后才能发表评论。


网站导航: