Foros de discusión

Handling concurrency in Liferay Cluster

Siby Mathew, modificado hace 7 años.

Handling concurrency in Liferay Cluster

Expert Mensajes: 268 Fecha de incorporación: 4/03/11 Mensajes recientes
Hello all,
I am working in a LR 6.2 CE GA4 Clustered environment.
The 2 nodes share the same DB with shared cache via portal-ext cluster configuration.
I have a scheduler invoking the method processMe() every 15 mins which can also be invoked by a user on clicking a page.

My requirement is to restrict concurrent call to this method.
I understand that synchronized blocks wont work due to the different JVMs.

Is there anything which I can reuse OOTB from within Liferay ? Can I reuse something from the JGroups Unicast/Multicast communication ?
Any other suggestions ?

Thanks,
Siby Mathew
thumbnail
David H Nebinger, modificado hace 7 años.

RE: Handling concurrency in Liferay Cluster

Liferay Legend Mensajes: 14916 Fecha de incorporación: 2/09/06 Mensajes recientes
Liferay uses jGroups for cluster messaging, so you may want to try out http://www.jgroups.org/manual/html/user-building-blocks.html#LockService.
Siby Mathew, modificado hace 7 años.

RE: Handling concurrency in Liferay Cluster

Expert Mensajes: 268 Fecha de incorporación: 4/03/11 Mensajes recientes
Thank you David for your suggestion.

Can I make use of the LockLocalServiceUtil provided by Liferay ?
I was trying to invoke the lock() method from two schedulers (concurrently fired for testing) after verifying isLocked()
At times during this test, both the schedulers were able to invoke the lock() method without any errors with the same className/Key Pair.

Any suggestions ?

Thanks,
Siby Mathew
Siby Mathew, modificado hace 7 años.

RE: Handling concurrency in Liferay Cluster (Respuesta)

Expert Mensajes: 268 Fecha de incorporación: 4/03/11 Mensajes recientes
Hello all,
I have found the solution after referring com.liferay.portal.kernel.backgroundtask.SerialBackgroundTaskExecutor.acquireLock() method.

The major change was to check
    if (!lock.isNew()) {
			throw new DuplicateLockException(lock);
		}


Basically even if two threads are able to invoke the lock() method, only one of the thread will be successful in creating the new object and the other will be just fetching the existing lock object. Hence lock.isNew() should find the thread which is holding the real lock.
Refer the above mentioned liferay class for more information.

Thanks for all your help.

Thanks,
Siby Mathew