Book Image

Getting Started with Hazelcast, Second Edition

By : Matthew Johns
Book Image

Getting Started with Hazelcast, Second Edition

By: Matthew Johns

Overview of this book

Table of Contents (19 chapters)
Getting Started with Hazelcast Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Distributed locking


When building a broad, horizontally scaled application, one aspect that we tend to lose is the ability to restrict and prevent concurrent activity across the whole application. Within a single JVM, we use a synchronized lock to guard a section of functionality from a concurrent execution. Once we move away from a single JVM, this problem becomes a much bigger issue. Traditional approaches would leverage a transactional database to provide a system for locking in the form of a table rowlock or a transactional state. However, this approach presents us with a single point of failure and contention issues when scaling up our application.

Hazelcast offers a distributed locking facility, allowing us to attempt acquiring a cluster-wide named lock, and guard the functionality behind it. If we can create an example class LockingExample, we can demonstrate this ability, as follows:

public class LockingExample {
  public static void main(String[] args) throws Exception {
    HazelcastInstance...