Creating Custom Locks


I wanna create an application whereby i can lock records or tables or both when one user is reading or making changes to the record and/or table. i wanna create custom locks each with their very own unique constraints/conditions and i wanna create it in the service… how do i go about doing that? how do create locks in Cuba and how do i add my custom constraints on them.


Hi Susan,

You can use the pessimistic locking described in the documentation. Below is an example of using this mechanism in a middleware service:

private LockManagerAPI lockManager;

public void someProcess() {
    LockInfo lockInfo = lockManager.lock("someProcess", "");
    if (lockInfo != null) {"Process is running by " + lockInfo.getUser() + " since " + lockInfo.getSince());
    try {
        // do something...
    } finally {
        lockManager.unlock("someProcess", "");

Hi Konstantin,

there is an error in this line:"Process is running by " + lockInfo.getUser() + " since " + lockInfo.getSince());

it say: “Log cannot be resolved to a type”

how do i fix that?

Thanks in advance.

Add log declaration to your class. See an example here:

this line:

LockInfo lockInfo = lockManager.lock(“someProcess”, “”);

what am i supposed to put between the Parentheses?

Anything. In the first place, the API is used for locking entities, and the parameters are used for entity name and ID (see Javadocs). In your case, the combination of parameters should uniquely denote your process or service.