MDA/MDD/TDD/DDD/DDDDDDD
          posts - 536, comments - 111, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          weblogic上HttpURLConnection的超時

          Posted on 2010-04-14 16:59 leekiang 閱讀(4186) 評論(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

          主站蜘蛛池模板: 墨脱县| 南乐县| 垫江县| 堆龙德庆县| 南安市| 西华县| 中宁县| 会泽县| 明星| 大城县| 四川省| 苗栗县| 库伦旗| 乳山市| 青州市| 海安县| 依兰县| 锡林浩特市| 汤原县| 阿克苏市| 平顺县| 宁南县| 青田县| 元江| 阳新县| 乌兰浩特市| 合作市| 沂水县| 盐池县| 扶绥县| 涟水县| 炎陵县| 澳门| 鲁山县| 宿松县| 陆丰市| 车险| 石景山区| 潼南县| 广元市| 盐津县|