Access Domino object with Java (2)

xiaoxiao2021-03-06  37

Execute thread by static method

To perform threads through a static method, you need to call SinitThread () to initialize the thread, call StermThread () to end the thread. The call of Stermthread () must be strictly coupled to the call of SinitThread (). It is recommended to put Stermthread () in the "Finally" block. Static methods are applicable to impossible for inheritance, or when you need to control event-driven threads.

import lotus.domino *;. public class myClass {public static void main (String argv []) {try {NotesThread.sinitThread (); // start thread Session s = NotesFactory.createSession (); // Operational code goes here} Catch (Exception E) {E.PrintStackTrace ();} finally {notesthread.stermthread (); // must terminate every thread}}}}

Each thread that performs local call must initialize a NotesThread object. It contains AWT threads that access the Domino object. The listening thread must use a static method because they cannot inherit from NotSthread.

Dynamically determine when both local calls and remote calls can dynamically determine when using static methods Sinitthread and Stermthread. Remote calls can also be performed when a local thread is running. But don't use objects you get in a session for calls for other sessions.

You should try to avoid multi-threaded use unless there is a very good reason. To follow the following principles:

Between the same session (SESSION), Domino's object will be automatically shared, synchronized, and recycled. If each thread uses a different session, these features are lost, and the synchronization and recycling of objects must be managed in each thread. Do not use dbdirectory across threads. • Access the same existing document in multithreading is allowed, but only access to a thread will simplify memory management. If the access to an existing document is restricted in one thread, it is possible not to check if other threads will be reclaimed. Creating a new document in a multi-thread is always secure, and the object used can be recycled regardless of the status of other threads. The brief table document is cached by thread. When multiple threads need to update the same concrete table document, the modifications made by the last updated thread will be saved. Pay special attention when deleting a document, as other threads may require this document to traverse the view or document collection. When the child object is used for other threads, all sub-threads have ended after the parent thread. This should be paid to this when using the Domino object in the AWT event processor.

Remote call

When calling the createSession, the first parameter uses a non-empty string, indicating that the remote call is performed. The first parameter represents the computer where the Domino server is located. E.g:

Session s = notesfactory.creatession ("myhost.east.acme.com")

or

Session s = notesfactory.creatession ("myhost.east.acme.com: 63148")

The port number is specified in the example in the back, so that the Web service is not required on the Domino server. Details See the "Get IOR" section later in this article.

To perform remote calls from an application or servlet, you must include ncso.jar. Ncso.jar contains Lotus.domino package, lotus.domino.cso package, lotus.domino.corba package, and ORB class. For installed Domino Designer and Domino servers, ncso.jar in the Domino / Java subdirectory in the Domino data directory. If Domino software is installed on your computer, you must manually copy this file from other computers. NCSO.jar must be included in the classpath, for example:

Set classpath: =% classpath%; C: /lotus/domino/data/domino/java/ncso.jar

Program

Remote call does not use Notesthread, just specify the hostname and port number (optional) in the CreateSession.

When do not use the thread, the program is approximately the following format:

Import lotus.domino. *; public class myclass {public static void main (string argv []) {Try {string host = "myhost.east.acme.com: 63148"; session s = notesfactory.createsis (HOST); / / Operational Code Goes Here} catch (exception e) {E.PrintStackTrace ();}}}

When using the thread, the program is:

Import Lotus.domino. *; public class myclass us (String argv []) {Myclass T = new myclass (); thread nt = new thread (Runnable) T); nt.start (); } Public void run () {Try {string host = "myhost.east.acme.com: 63148"; session s = notesfactory.createsis (host); // Operational code goes here} catch (exception e) {E.PrintStackTrace ();}}} (Source IBM official website)

转载请注明原文地址:https://www.9cbs.com/read-62249.html

New Post(0)