There are more alternatives for locking within distributed environment.
Zookeeper:
https://zookeeper.apache.org/doc/r3.3.6/recipes.html
or you can use Redis, for example.
https://redis.io/topics/distlock
Please read and following comments regarding Redis locking:
http://martin.kleppmann.com/2016/02/08/how-to-do-distributed-locking.html
http://antirez.com/news/101
Zookeeper:
https://zookeeper.apache.org/doc/r3.3.6/recipes.html
or you can use Redis, for example.
https://redis.io/topics/distlock
Please read and following comments regarding Redis locking:
http://martin.kleppmann.com/2016/02/08/how-to-do-distributed-locking.html
http://antirez.com/news/101