Domino JVM等相关问题

来源:http://www-01.ibm.com/support/docview.wss?uid=swg21097861
http://www-01.ibm.com/support/docview.wss?uid=swg27002721
http://blog.csdn.net/ygxxingxing/archive/2007/11/16/1888945.aspx

Why it is important to use Recycle() method on every Java object

 Technote (FAQ)
 
 
Question
You want to use Java in either an agent, a servlet, an applet, or a standalone application to access Lotus Notes'® objects for information locally on the same server.
The above applets mimic the LotusScript object model to make it easier for developers to use these tools. For example, to get a handle on a database using LotusScript or Java classes, the session contains the current database. Once you create a session, you can reference a database through the session.

However, it is very important to recycle every object that is created for maximum system performance. When is it best to invoke the Recycle() method for this and other Java objects?
 
 
Answer
Creating an object in LotusScript:
When you create an object in LotusScript, you create two objects: one in LotusScript and one in the Notes backend (C++ code). The LotusScript object "points" to the C++ object which really implements the class behavior. When the LotusScript agent or event ends, both objects are destroyed automatically. If the objects were not eliminated, they would stay resident in memory, thereby creating a memory leak.

Creating an object in Java:
If you create an object in Java, the same applies. This object is a pointer that points to an object that is created in C++. It is common in pure Java coding to set something to Null in order for it to be flagged for garbage collection (gc) immediately. This is called "aggressive" garbage collection.

However, when using Notes objects for Java, setting something to Null marks the Java object for garbage collection but does not mark the C++ object for garbage collection. Dereferencing the Java object flags it for garbage collection but nothing will be affected on the C++ object.

Why recycle?
Recycle() destroys the C++ object and sets the Java object for garbage collection. If you mark objects Null, you can still experience memory issues. When using objects in an agent, all objects (both Java and C++) are destroyed when the agent ends. When using servlets, .jsp's, or standalone applications, recycle must be used since Domino will never clean up these backend objects.

Conversely, if an object is set to be recycled, it will not be marked Null. In theory, you could reference the object again and it wouldn't crash, just merely throw an exception. This is important when there are multiple references to the same object; "db = mydb.nsf" as well as, "db = yourdb.nsf". Redefining your reference in this way is not recommended since it can be confusing and yield unreliable results.

It is important to understand what objects are created, what they are set to, and when they are used. Objects form a hierarchy. For example, recycling a parent document also recycles its children. Since the session object is at the top of the hierarchy, recycling the session will recycle everything that is used from it.

Finding objects:
Go to the Design pane in Domino Designer, click in the code area, and do a Find on "recycle" or the object for which you are searching. Set the scope of the Find for current or all objects.

If you do a search for Recycle()s and don't find any, you can remedy the situation by having a developer go through and add the code below to all objects after they are finished being used. One thing to watch out for is the use of New being instantiated in a loop. For every iteration of the loop, a new object is created. Unless you recycle the object within the loop, this object will stay resident in memory.

NOTE: The code below is a sample script, provided to illustrate one way to approach this issue. It is to be used as is and at your own risk. In order for this example to perform as intended, the script must be laid out exactly as indicated below. Product Support cannot customize this script for specific environments or applications.

Example of using Recycle() within a loop and using aggressive garbage collection:
  •  
    • try {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();
      Database db = agentContext.getCurrentDatabase();
      View v = db.getView("SomeView");
    •  
      • {
        e.printStackTrace();
        }
    • 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) }
  • import lotus.domino.*;
    public class JavaAgent extends AgentBase {
    public void NotesMain() { // 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
    }
 
 
 
 
Historical Number
186643
 
 

 


 

 

Java/CORBA and JVM Variables

 Periodical
 
Abstract
This article resides in "Iris Today," the technical Webzine located on the http://www.notes.net Web site produced by Iris Associates, the developers of Domino/Notes. Please visit Notes.net to obtain both the latest version of this article as well as other related articles. Java/CORBA and JVM variables
by Professor INI In response to a number of programming related questions, Professor INI decided to run through all the programming related NOTES.INI variables. Last month, we looked at variables
 
 
Content

This article resides in "Iris Today," the technical Webzine located on the http://www.notes.net Web site produced by Iris Associates, the developers of Domino/Notes. Please visit Notes.net to obtain both the latest version of this article as well as other related articles.

Java/CORBA and JVM variables
by Professor INI

Ask Professor INIIn response to a number of programming related questions, Professor INI decided to run through all the programming related NOTES.INI variables. Last month, we looked at variables associated with LotusScript, Lotus Connectors, and the formula language. This month, we move on to variables that relate to Java and answer the question:

Q: I'm a Notes/Domino applications developer just starting to use Java. What Designer NOTES.INI variables can I use that will help me with my programming?


Java access to Domino objects (through CORBA), although not actually part of the Designer Integrated Development Environment, relies on Designer for compilation and a Domino server at runtime (for applications). This article addresses the NOTES.INI variables affecting Java/CORBA and the JVM.

Note:
NOTES.INI variables related to debugging are not addressed in this article. For more information concerning NOTES.INI debug variables, see the Ask Professor INI column, Using debugging variables.

Most of the variables discussed in this article are Notes and Domino R5 NOTES.INI variables. We've included some Rnext-only variables (these are so noted), but please keep in mind that Rnext-only variables are works in progress and, therefore, are subject to change before Rnext is released.

Much of the information contained in this article can be found in Domino R5 Designer Help. However, additional details were gleaned through discussions with the developers and are not documented.

A few of the variables mentioned here are set through the client's user interface (these are so noted), but most are set by modifying the NOTES.INI file directly (for example, by using a text editor). In general, we discourage editing the NOTES.INI file directly because of the damage that can be done by modifying it incorrectly. If you find you need to edit the NOTES.INI file directly, do so with caution and great care.

Variables and Java/CORBA

Using Java to access Domino Objects requires that a few NOTES.INI variables be set. Also, see the section on Variables and the JVM for more Java-related NOTES.INI variables.

Note:
Do not confuse this interface with the Lotus Domino Toolkit for Java/CORBA, which will be discussed in a subsequent article.

Allow_Notes_Package_Applets

This variable allows you to use Notes packages in your Java applications. Its syntax is:

Allow_Notes_Package_Applets=1

This variable is set in the client's NOTES.INI file.

JavaDlgSettings

To assist you in creating a Java agent, this variable, when set to 1, is used to "remember" the last set of options you used in the Edit Project dialog box. Its syntax is:

JavaDlgSettings=1

This variable is set in the client's NOTES.INI file.

JavaUserClasses

If your Java agent calls another class that has native methods, you must make sure that that class is loaded via the JVM's system loader. To ensure this, set this variable to the file name of the class file that contains the native methods. The variable's syntax is:

JavaUserClasses=<directory/filename>

By setting this variable, you override a security restriction contained in the agent class loader that does not allow classes with native methods to be loaded. This variable may be set in either or both the client and the server NOTES.INI file.

Note that you should not enter more than one JavaUserClasses entry in a NOTES.INI file. If you have more than one, only the first will be used; all others will be ignored. If you have multiple uses for JavaUserClasses, enter all the parameters on the same line. For example:

JavaUserClasses=<directory1>;<directory2/jarfile>;<zipfile1>;…

Keep in mind that there is a 256-byte limit for NOTES.INI entries. Use JavaUserClasses sparingly.

EnableJavaApplets

This variable enables Java applets if set to 1 or disables them if set to 0. You set this variable to 1 by selecting the Enable Java applets option in the Additional Options section of the Basics panel of the User Preferences dialog box. Deselecting Enable Java applets sets the variable to 0.

LaunchDIIOPOnPreview

DIIOP (Domino Internet Inter-ORB Protocol) is a server task that works with the Domino Object Request Broker. When set to 1, this variable launches the DIIOP server task when Preview In a Browser is selected from Domino Designer.

You set this variable to 1 by selecting "Launch the CORBA (DIIOP) server on Preview in a web browser" option in the Additional Options section of the Basics panel of the User Preferences dialog box. Deselecting "Launch the CORBA (DIIOP) server on Preview in a web browser" causes this variable to be removed from the NOTES.INI file.

ServerTasks

In general, this variable must be set for anything to run on the server. Setting it to http and diiop ensures that the server tasks HTTP and DIIOP are running. Java/CORBA requires that these server tasks be running. Its syntax is:

ServerTasks=<any other tasks>, http, diiop

where <any other tasks> are any other needed server tasks. This variable is set in the server NOTES.INI file.

Environment variables

Java/CORBA classes include the following NOTES.INI variable-related functionality:
  • The getEnvironmentString (for strings and numeric values) and getEnvironmentValue (for numeric values) methods of the Session class retrieve the value of an environment variable from the current user's NOTES.INI file.
  • The setEnvironmentVar method of the Session class sets the value of a string or numeric environment variable.

Variables and the JVM

There are several variables used to control the behavior of the Java Virtual Machine (JVM). All of these variables can be set in either or both the client and server NOTES.INI file. The client's NOTES.INI values rule the JVM executing on the client, such as local Java agents and applets. The server's NOTES.INI values rule all the JVM's running on the server—one each in http, amgr, server, router, runjava, and so on, or in some combination. It is unlikely, however, that you will ever need to set any of these variables (except for perhaps JavaUserClasses). As ever, proceed with caution when editing a NOTES.INI file.

JavaEnableJIT

By default, Notes disables the JVM default JIT (Just-In-Time) functionality because of its instability (see the caution below). Setting this variable to 1 turns on the default JIT functionality, if one is provided; so the JVM will allow normal loading of the default JIT. The variable's syntax is:

JavaEnableJIT=1

Caution:
JIT functionality can be unstable and lead to unexpected crashes.

JavaJITName

Setting this variable turns on the JIT specified in the parameter. Its syntax is:

JavaJITName=<jit_name>

where <jit_name> is the specific JIT to use. You must provide the named JIT or an error is reported by the JVM, although execution of the application or agent will continue without it.

You can specify the default JIT name here, such as symcjit on Win32 or jitcompiler on alpha; that is equivalent to using JavaEnableJIT=1.

Note:
The name of the JIT on Win32 differs depending on what version of Notes you are referring to. On 5.0.x, the JIT name is symcjit. On Rnext, its name is jitc.

JavaMaxHeapSize

Use this variable to specify the maximum size the Java heap can grow to in bytes. Its syntax is:

JavaMaxHeapSize=<number_of_bytes>

The default number of bytes is 67,108,864 (64MB). Note that this is the maximum size, not the initial size. (Currently, there is no way to set the initial size.) The JVM starts out at 1MB of heap space, most of it uncommitted. If the JVM needs more heap space than it currently has, it expands the heap in increments, although it will not exceed the maximum. An exception like java.lang.OutOfMemoryError is an indication of maxed-out heap space.

JavaNoClassGC

Use this variable to turn off the garbage collection (GC) of unreferenced classes. Its syntax is:

JavaNoClassGC=1

For example, you might turn garbage collection of classes off to protect static fields. If a class has static fields that are used by others, and garbage collection is performed on that class, it could lead to potential unintended changes in the static fields.

You can use this variable to stop failures due to poorly written code, for instance, code that relies on static fields with no continuity of class referencing. Properly designed code will work properly regardless of the state of this variable.

JavaStackSize

You can use this variable to specify the size of each Java thread's execution stack. Its syntax is:

JavaStackSize=<number_of_bytes>

The default size of a Java thread's execution stack is 409,600 (or 400K), which is fine for most purposes. However, if you need to use deeply nested call stacks (such as recursion), then you may need to increase the stack size.

JavaUserClasses

The variable is set to a list of directories or JAR or ZIP files that are added to the CLASSPATH at JVM startup so that classes can be found via the system loader rather than attached to the agent or applet. This allows code sharing across databases. The variable's syntax is:

JavaUserClasses=<directory1>;<directory2/jarfile>;<zipfile1>;...

The list is semicolon ( ; ) delimited on Win32 and OS/2 system and colon ( : ) delimited on Unix systems. For example, the following is a valid list on a Win32 system:

JavaUserClasses=c:/classes;d:/appxyz/stuff.jar

Be aware that one drawback to using this variable is that, because it is in the NOTES.INI file, it doesn't replicate. If you have an agent, applet, or servlet that relies on JavaUserClasses, and the database that contains that item replicates somewhere, you have to manually add JavaUserClasses to the NOTES.INI file on the target system or the agent, applet, or servlet won't run. Another drawback is that the variable requires that the user have access to the file system on the server.

Note that you should not enter more than one JavaUserClasses entry in a NOTES.INI file. If you have more than one, only the first will be used; all others will be ignored. If you have multiple uses for JavaUserClasses, enter all the parameters on the same line, as shown in the syntax above.

Keep in mind that there is a 256-byte limit for NOTES.INI entries. Use JavaUserClasses sparingly.

JavaVerbose

Use this variable to turn on the verbose setting of the JVM. Its syntax is:

JavaVerbose=1

This causes numerous messages to be issued by the JVM during its execution, which can be helpful in narrowing down runtime problems.

JavaVerboseGC

Use this variable to turn on extra messages from the GC mechanism in the JVM. Its syntax is:

JavaVerboseGC=1

During garbage collection, the JVM issues many informational messages about memory use. These can be helpful for debugging heap allocation problems, such as the unbounded growth of the heap leading to OutOfMemoryErrors.

JavaVerboseJNI

This is a new variable in Rnext. Use this variable to turn on extra messages from the Java Native Interface mechanism in the JVM. Its syntax is:

JavaVerboseJNI=1

During calls to JNI functions, the JVM issues many informational messages about what is happening. These can be helpful for debugging native code and for getting extended JNI-related information out of the JVM at runtime.

Variables related to the JVM verifier

The verifier is a piece of the JVM that inspects a given piece of bytecode to make sure it complies with the spec and doesn't do anything that code shouldn't do. The default behavior of the JVM is to verify just bytecode that is loaded remotely. These next three variables control verifier behavior.

JavaVerify

Use this variable to tell the JVM to verify all bytecode it loads, not just the bytecode loaded remotely. Its syntax is:

JavaVerify=1

Because this verification of non-remotely loaded code results in a performance hit, it is not the default behavior.

JavaNoVerify

Use this variable to turn off all bytecode verification. Its syntax is:

JavaNoVerify=1

Caution:
The verifier is an essential part of Java's security mechanism. Turning it off will improve performance, but it will also leave you with a gaping security hole and no protection against code inadvertently getting corrupted in transfer. Although available and supported, this variable should seldom, if ever, be used.

JavaVerifyRemote

Use this variable to tell the JVM to run verification on classes that are loaded remotely, for example, via a classloader. Its syntax is:

JavaVerifyRemote=1

Although the current default for the JVM is to have verification of remotely loaded bytecode on, this variable has been included to ensure that this option can be enabled if the default setting ever changes.

Conclusion

This concludes the second part of our exploration of NOTES.INI variables and programmability. In a future column, we will discuss NOTES.INI variables and the Notes & Domino programming toolkits.

Do you have a NOTES.INI question? Send it in to Professor INI. We'll answer as many questions as we can in future "Ask Professor INI" columns. Keep in mind, however, that we may not be able to answer every question, nor can we quickly respond to requests that require immediate attention. If you need an immediate response to a question, we recommend you post it in the
Iris Cafe Notes/Domino Gold Release Forum where someone from the general Notes community might be able to help, or contact Lotus Customer Support.


Related Documents:
  •  
    •  
      •  
        •  
 
 
 
Cross Reference information
SegmentProductComponentPlatformVersionEdition
Messaging ApplicationsLotus End of Support ProductsLotus Domino Designer 5.0 
 

 

 

 


 

 

 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

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值