Domino JVM异常

问题描述:在OA中,分别出现了下列异常。
异常一:

异常二:

异常三:
2007-10-25 09:45:47   HTTP JVM: -->java.lang.OutOfMemoryError: JVMCI015:OutOfMemoryError, cannot create anymore threads due to memory or resource constraints
错误分析:根据上面提示信息,可以初步断定一是服务器内存或虚拟内存不足,二是domino自带的java虚拟机
出了问题。在网上查阅资料,发现主要原因是domino自带的java虚拟机不会自动释放资源,导致虚拟机内存耗
尽,在调用java代理时出现溢出。

官方说明:
Each document opened in an agent allocates a private handle. When the document is closed by 
the agent, the handle is freed. Loops can be tricky. If the document isn''t closed after processing, a handle will be allocated for every document processed in the loop. 
This isn''t a concern in small databases with few documents processed, but in larger databases,
 it can become an issue.
之后在designer帮助中,找到:
Java has no knowlege of the heavyweight back-end Domino Objects, only the lightweight Java 
objects representing them. Garbage collection has no effect on Domino Objects unless you first
 explicitly recycle them.

解决方案:
 用LS代理代替所有java代理,这是维持系统稳定的最好方案,在万不得已要用java代理时可以采取下列
方案补救,但不排除发生异常的可能。
 1.及时地对所用到Notes Object(session,agentContext,db,view,document. 等等)进行Recycle()
处理。在代理调用完成时再进行System.gc();System.finalize()。
可以参考IBM网站上的这篇文章:
http://www-1.ibm.com/support/docview.wss?uid=swg21097861;
 2.在循环中要注意及时的释放资源:
 while (Doc != null)
 {
  middleDoc = docView.getNextDocument(Doc);
  cal = session.evaluate(config.arc_delete_fomular, Doc);
  if (cal.get(0).toString().equals("1.0"))
  {
   correspond += 1;
  }
  Doc.recycle();
  Doc = null;
  Doc = middleDoc;
  if (correspond >= config.maxArchive) break;
 }
 3.在服务器的 notes.ini 文件中,可以增加一个参数:JavaMaxHeapSize=<字节数> 
这个参数的具体数值应该根据服务器的硬件环境和应用程序的实际需要来调整,默认的值应该是64M,可以根据
情况适当往大调一下。例如,“JavaMaxHeapSize=268435456” 将此值设为256MB。
注意:domino只能用4GB的内存,增加或修改此参数后,应重新启动Domino服务器。
 4.对于jar包的调用,最好放在notes.ini文件中,而不是在编写Java Agent的过程中处理,我们可以将
所调用到的jar文件丛中删除,在notes.ini文件中增加JavaUserClasses=pathjarFile,具体可以参考IBM网站
上的这篇文章:
http://www-1.ibm.com/support/docview.wss?uid=swg27002721;
 5.监控JVM内存使用情况。
通过 Runtime.getRuntime().totalMemory() ,Runtime.getRuntime().freeMemory()可以查看JVM内存
使用情况;在notes.ini文件中增加了JavaVerboseGC = 1的参数,每次在执行该代理的时候观察内存泄漏的情况。
 6.升级domino。理论上IBM会对产品的BUG进行修正,但遗憾的是目前无相关补丁资料及稳定版本信息。

参考资料:
 http://blog.csdn.net/wangdeq/archive/2007/10/10/1818246.aspx

 http://blog.csdn.net/xaser/archive/2005/11/15/529684.aspx

 http://www.hur.cn/program/bbs/Lotus/200601/662594.html

 http://topic.csdn.net/t/20040706/15/3150188.html

 http://blog.chinaunix.net/u/11279/showart_60477.html

附:下面是一段利用ODBC连接数据库的程序,自己看看ODBCResultSet类的用法,你就可以读取、写入、修改、
删除数据等等。   
  Uselsx   "*LSXODBC" 
  Dim   con   As     ODBCConnection   
  Dim   qry   As     ODBCQuery   
  Set   con   =   New   ODBCConnection   
  con.SilentMode   =   False   
  Print   "正在连接关系数据库..."   
  If   con.ConnectTo("ODBCSource","sa","123")   =   False   Then  //ODBC数据源名、用户名、口令   
  Print   "连接数据库失败!"   
  Exit   Sub   
  End   If   
  Print   "关系数据库连接成功!"   
    
  Dim   result   As   ODBCResultSet   
  Set   qry   =   New   ODBCQuery   
  Set   qry.Connection   =   con   
    
  Set   result   =   New   ODBCResultSet   
  Set   result.Query   =   qry   
  StrSQL   =   "SELECT   *   FROM   drug"         
  qry.SQL   =   StrSQL   
  If   result.Execute   =   False   Then   
  Print   "无法从数据表提取数据!"   
  Exit   Sub   
  End   If   
  con.Disconnect

--------------------------------------------------------------

Example of usin Recycle() within a loop and using aggressive garbage collection: 

  • import lotus.domino.*; 
    public class JavaAgent extends AgentBase { 
    public void NotesMain() {
    • try { 
      Session session = getSession(); 
      AgentContext agentContext = session.getAgentContext(); 
      Database db = agentContext.getCurrentDatabase(); 
      View v = db.getView("SomeView");
    // turn off auto-update so that if we make a change to a document // and resave, it won't affect the sort order in the view 
    v.setAutoUpdate(false); 

    Document doc = v.getFirstDocument(); 
    Document temp = null;   
    //sets the temp for garbage collection immediately 
    • while (doc != null) 

      // do something with the document here... 
      // whatever, just don't delete it (yet)! 
      temp = v.getNextDocument(doc);   // get the next one 
      doc.recycle();  // recycle the one we're done with 
      doc = temp; 

      // end while 

      } catch(Exception e)

      • e.printStackTrace(); 
        }
      }
    }

猜你喜欢

转载自blog.csdn.net/bluecard2008/article/details/81168288