amp@java

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            99 隨筆 :: 0 文章 :: 228 評論 :: 0 Trackbacks
          Tomcat的Release Notes 里有這么一段話:
          =======================
          JNI Based Applications:
          =======================
          Applications that require native libraries must ensure that the libraries have
          been loaded prior to use.? Typically, this is done with a call like:

          ? static {
          ??? System.loadLibrary("path-to-library-file");
          ? }

          in some class.? However, the application must also ensure that the library is
          not loaded more than once.? If the above code were placed in a class inside
          the web application (i.e. under /WEB-INF/classes or /WEB-INF/lib), and the
          application were reloaded, the loadLibrary() call would be attempted a second
          time.

          To avoid this problem, place classes that load native libraries outside of the
          web application, and ensure that the loadLibrary() call is executed only once
          during the lifetime of a particular JVM.

          簡單地說就是JNI庫的加載在啟動Tomcat的JVM中只能進行一次,如果兩次執行System.loadLibrary("path-to-library-file");將會導致錯誤(Error,不是Exception):
          java.lang.UnsatisfiedLinkError:

          Native Library xxx.dll already loaded in another classloader
          可是這段話并沒有給出具體的解決辦法。我要使用的一個NT登錄驗證的JAAS模塊碰到了這個問題:我把包含這個語句的庫放在了某個web應用程序的lib目錄下,結果當修改了某個web配置文件導致這個程序的context reload時,JAAS模塊就不能使用,因為它又重新加載JNI庫導致錯誤。只有重新啟動整個tomcat才能恢復正常,十分麻煩。
          找了好久,終于在一個大俠的文章(http://cuiyingfeng.blog.ccidnet.com/blog/ccid/do_showone/tid_48232.html)中找到了解決方法:
          1、加載JNI庫的包放在Tomcat的common/lib目錄下,而不要放在各context的lib目錄下;
          2、每次加載JNI庫之前檢查是否已經加載過。
          由于加載語句不是我能控制的,所以第二種方法不能實現,于是我就通過第一種方法把這個問題解決了。

          posted on 2006-08-31 11:13 amp@java 閱讀(4923) 評論(0)  編輯  收藏 所屬分類: JSF
          主站蜘蛛池模板: 六盘水市| 青铜峡市| 永丰县| 宜章县| 应城市| 宁阳县| 博野县| 双峰县| 白河县| 阳高县| 常熟市| 泗阳县| 察雅县| 永济市| 枣强县| 西城区| 鄂伦春自治旗| 泸州市| 古丈县| 桂林市| 大悟县| 昆山市| 延边| 绥江县| 武宁县| 元江| 通江县| 来安县| 澳门| 西华县| 南江县| 桦川县| 荥经县| 凌源市| 嘉鱼县| 雅安市| 定州市| 寿光市| 吉水县| 红安县| 滕州市|