concurrent locking strategy

22 views
Skip to first unread message

Paul Blakeley

unread,
Oct 17, 2016, 3:14:48 PM10/17/16
to Grails Dev Discuss
Hi,
  I am currently working on a project that has multiple users that can modify store items.  I would like to code a solution that would lock an item from being modified once another user starts to modify its contents.  I would to highlight this through some rendered html on the store item list page. I wondered if someone has had previously experienced doing this kind of thing and possibly sharing their solution with me? 

Gregory Dickson

unread,
Oct 18, 2016, 1:06:56 PM10/18/16
to Grails Dev Discuss
You should review the Grails/GORM docs on versioning and optimistic locking: http://docs.grails.org/3.1.10/guide/GORM.html#optimisticLockingAndVersioning

One time I wanted to absolutely lock a row for an indefinite period of time. So, I created a field called 'status' on the domain object and then I would do a manual .lock() (see GORM documentation) on the object, update the field to 'locked', .save() the domain object, then when the user could 'own' it for an indefinite amount of time, and when they finished with that object, they would update it to another status.

I would recommend reading all the Grails and GORM documentation on locking, pessimistic/optimistic and especially, object versioning. Also, you can try the Grails Slack channel as you might find other input.

Paul Blakeley

unread,
Oct 18, 2016, 4:15:52 PM10/18/16
to Grails Dev Discuss
Thank you for your comprehensive answer.  That helps.  I have read about the optimistic and pessimistic locking.  With respect to the .lock method(pessimistic locking) I was under the impression that the lock would effectively be unlocked on the completion of the transaction??? Which is not really desirable for me. 

Gregory Dickson

unread,
Oct 18, 2016, 5:11:16 PM10/18/16
to grails-de...@googlegroups.com
yes, .lock() is only scoped to the request/response scope.



--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-disc...@googlegroups.com.
To post to this group, send email to grails-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/e65f4f97-284f-4912-a567-a69d5c5ab520%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages