This class for syncronization in Lotusscript, create Lock for document by document ID. Implement functional: only one agent can simultaneously change document or documents under the lockID to database.
Class classSynchronization
Private lockName As String
Private lockID As Integer
Function getCount As long
getCount = CodeLockCheck(Me.lockID)
End Function
Function Wait As Boolean
Wait = CodeLock(Me.lockID)
End Function
Sub New( lockNameID As String)
Me.lockName = lockNameID
Me.lockID = CreateLock(Me.lockName)
' MsgBox "Synchronization Lock: "+ Me.lockName+ " Count in queue: " + CStr (CodeLockCheck(Me.lockID) )
End Sub
Sub Delete()
Dim releaseLock As Boolean
Dim deleteLock As Boolean
' MsgBox "Synchronization Release Lock: "+ Me.lockName+ " Count in queue: " + CStr (CodeLockCheck(Me.lockID) )
' When we are finished, destroy this reference to the lock
releaseLock = CodeUnlock(Me.lockID)
deleteLock = DestroyLock(Me.lockID)
End Sub
End Class
How to convert this class to Java class in domino?
There are no direct Java equivalents to the builtin locking (CodeLock, CodeUnLock, DestroyLock, CreateLock, DestroyLock...) functions in LotusScript. You will need to learn about Java's synchronization primitives, analyze your application's synchronization requirements, and find the best fit to accomplish what your application requires.
No Effect
import lotus.domino.*;
import java.util.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Document doc = agentContext.getDocumentContext();
String lock = doc.getNoteID();
synchronized (lock) {
for (int i = 1; i < 10; i++){
System.out.println(lock + " " + session.getEffectiveUserName() + " " + Integer.toString(i));
Thread.sleep(1000);
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
Result:
[002413:000171-00007F99DC253700] 12/03/2021 11:47:51 PM HTTP JVM: 46AFE CN=Administrator/O=test 1
[002413:000171-00007F99DC253700] 12/03/2021 11:47:52 PM HTTP JVM: 46AFE CN=Administrator/O=test 2
[002413:000171-00007F99DC253700] 12/03/2021 11:47:53 PM HTTP JVM: 46AFE CN=Administrator/O=test 3
[002413:000173-00007F99DC4C7700] 12/03/2021 11:47:54 PM HTTP JVM: 46AFE CN=User 3/O=test 1
[002413:000171-00007F99DC253700] 12/03/2021 11:47:54 PM HTTP JVM: 46AFE CN=Administrator/O=test 4
[002413:000173-00007F99DC4C7700] 12/03/2021 11:47:55 PM HTTP JVM: 46AFE CN=User 3/O=test 2
[002413:000171-00007F99DC253700] 12/03/2021 11:47:55 PM HTTP JVM: 46AFE CN=Administrator/O=test 5
[002413:000173-00007F99DC4C7700] 12/03/2021 11:47:56 PM HTTP JVM: 46AFE CN=User 3/O=test 3
[002413:000171-00007F99DC253700] 12/03/2021 11:47:56 PM HTTP JVM: 46AFE CN=Administrator/O=test 6
[002413:000173-00007F99DC4C7700] 12/03/2021 11:47:57 PM HTTP JVM: 46AFE CN=User 3/O=test 4
[002413:000171-00007F99DC253700] 12/03/2021 11:47:57 PM HTTP JVM: 46AFE CN=Administrator/O=test 7
[002413:000173-00007F99DC4C7700] 12/03/2021 11:47:58 PM HTTP JVM: 46AFE CN=User 3/O=test 5
[002413:000171-00007F99DC253700] 12/03/2021 11:47:58 PM HTTP JVM: 46AFE CN=Administrator/O=test 8
[002413:000173-00007F99DC4C7700] 12/03/2021 11:47:59 PM HTTP JVM: 46AFE CN=User 3/O=test 6
[002413:000171-00007F99DC253700] 12/03/2021 11:47:59 PM HTTP JVM: 46AFE CN=Administrator/O=test 9
[002413:000173-00007F99DC4C7700] 12/03/2021 11:48:00 PM HTTP JVM: 46AFE CN=User 3/O=test 7
[002413:000173-00007F99DC4C7700] 12/03/2021 11:48:01 PM HTTP JVM: 46AFE CN=User 3/O=test 8
[002413:000173-00007F99DC4C7700] 12/03/2021 11:48:02 PM HTTP JVM: 46AFE CN=User 3/O=test 9
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.