SlideShare a Scribd company logo
Hazelcast Distributed Lock
Jadson Santos
Problem
• Some times you need a critical region in your system
where 2 threads can not access this part of code
concurrently, or something wrong will happen
•
• The easiest way to do this, is used the Java synchronized
block:
20/03/17 Hazelcast distributed lock
Problem
• The problem with this approach is that it just work in the
same Java Virtual Machine.
•
• What can we do if we have several instances of our
application running?
•
20/03/17 Hazelcast distributed lock
DataBase Distributed Lock
• The first option is use database based lock
•
• With Hibernate we have something like this:
•
20/03/17 Hazelcast distributed lock
DataBase Distributed Lock
• If two threads call the findObjectLock method at same
time, the second one you will wait until the first transaction
is closed.
•
• But if we have several databases or we can not use the
lock of the database?
•
20/03/17 Hazelcast distributed lock
HazelCast Distributed Lock
• The Hazelcast IMDG operational in-memory computing
platform helps leading companies worldwide manage their
data and distribute processing using in-memory storage
and parallel execution for breakthrough application speed
and scale [1].
•
• Hazelcast implement a distributed version of some Java
data structures like Maps, Set, Lists, Queue and Lock
•
20/03/17 Hazelcast distributed lock
HazelCast Distributed Lock
• ILock is the distributed implementation of
java.util.concurrent.locks.Lock. Meaning if you lock using
an ILock, the critical section that it guards is guaranteed
to be executed by only one thread in the entire cluster [2].
•
20/03/17 Hazelcast distributed lock
Configuring HazelCast
• Just add a simple Jar to the application classpath.
•
• With Gradle stay like this:
•
20/03/17 Hazelcast distributed lock
Configuring HazelCast Cluster
• Programmatically you need initiated a Config object for
the HazelCast instance
•
•
•
•
•
• First of all, we choose the cluster initial port number and
the number of ports the cluster we use.
•
• If you have several threads at same time access the
cluster, it is necessary have several ports
•
20/03/17 Hazelcast distributed lock
Configuring HazelCast Cluster
• After that, we need to chose if use Multicast or specific
IPs addresses in the cluster, we configure to use specific
IPs
•
•
•
•
•
•
•
20/03/17 Hazelcast distributed lock
Configuring HazelCast Cluster
• Now we inform these specific IPs to the cluster
•
•
•
•
•
•
•
20/03/17 Hazelcast distributed lock
Configuring HazelCast Cluster
• At last, we specify which network interfaces that
Hazelcast should use
•
•
•
•
•
•
•
20/03/17 Hazelcast distributed lock
Configuring HazelCast Cluster
• We can now instantiate a new Hazelcast Instance with
this configuration, how iniciate a Hazelcast instance is
slow, takes around 3 seconds, we initialized just one
instance per JVM
20/03/17 Hazelcast distributed lock
Configuring HazelCast Cluster
• The complete code:
20/03/17 Hazelcast distributed lock
Using HazelCast Cluster
• You must call HazelCast lock in a try-finally block to
ensure that the lock will be release.
• The lock have an identifier, so we can have different locks
in the same cluster
20/03/17 Hazelcast distributed lock
References
• [1] Hazelcast IMDG. The Leading Open Source In-
Memory Data Grid. https://hazelcast.org/
•
• [2] Lock
http://docs.hazelcast.org/docs/3.5/manual/html/lock.html
20/03/17 Hazelcast distributed lock

More Related Content

What's hot (20)

PPTX
Introduction to ML with Apache Spark MLlib
Taras Matyashovsky
 
PDF
[Outdated] Secrets of Performance Tuning Java on Kubernetes
Bruno Borges
 
PDF
Cloud Native ClickHouse at Scale--Using the Altinity Kubernetes Operator-2022...
Altinity Ltd
 
PDF
Transaction Management on Cassandra
Scalar, Inc.
 
PDF
Introduction to Redis
Dvir Volk
 
PDF
M|18 Architectural Overview: MariaDB MaxScale
MariaDB plc
 
PPTX
Evening out the uneven: dealing with skew in Flink
Flink Forward
 
PDF
Parquet performance tuning: the missing guide
Ryan Blue
 
PDF
Nifi
Julio Castro
 
PDF
Kafka Lag Monitoring For Human Beings (Elad Leev, AppsFlyer) Kafka Summit 2020
HostedbyConfluent
 
PPTX
Hadoop REST API Security with Apache Knox Gateway
DataWorks Summit
 
PPTX
Introduction to Apache Kafka
Jeff Holoman
 
PPTX
Hadoop Meetup Jan 2019 - Overview of Ozone
Erik Krogen
 
PDF
AF Ceph: Ceph Performance Analysis and Improvement on Flash
Ceph Community
 
PPTX
OpenTelemetry For Developers
Kevin Brockhoff
 
PDF
Apache Kafka Fundamentals for Architects, Admins and Developers
confluent
 
PDF
Intro to HBase
alexbaranau
 
PDF
Room 2 - 6 - Đinh Tuấn Phong - Migrate opensource database to Kubernetes easi...
Vietnam Open Infrastructure User Group
 
PPTX
Kafka at Peak Performance
Todd Palino
 
PDF
Deploying Flink on Kubernetes - David Anderson
Ververica
 
Introduction to ML with Apache Spark MLlib
Taras Matyashovsky
 
[Outdated] Secrets of Performance Tuning Java on Kubernetes
Bruno Borges
 
Cloud Native ClickHouse at Scale--Using the Altinity Kubernetes Operator-2022...
Altinity Ltd
 
Transaction Management on Cassandra
Scalar, Inc.
 
Introduction to Redis
Dvir Volk
 
M|18 Architectural Overview: MariaDB MaxScale
MariaDB plc
 
Evening out the uneven: dealing with skew in Flink
Flink Forward
 
Parquet performance tuning: the missing guide
Ryan Blue
 
Kafka Lag Monitoring For Human Beings (Elad Leev, AppsFlyer) Kafka Summit 2020
HostedbyConfluent
 
Hadoop REST API Security with Apache Knox Gateway
DataWorks Summit
 
Introduction to Apache Kafka
Jeff Holoman
 
Hadoop Meetup Jan 2019 - Overview of Ozone
Erik Krogen
 
AF Ceph: Ceph Performance Analysis and Improvement on Flash
Ceph Community
 
OpenTelemetry For Developers
Kevin Brockhoff
 
Apache Kafka Fundamentals for Architects, Admins and Developers
confluent
 
Intro to HBase
alexbaranau
 
Room 2 - 6 - Đinh Tuấn Phong - Migrate opensource database to Kubernetes easi...
Vietnam Open Infrastructure User Group
 
Kafka at Peak Performance
Todd Palino
 
Deploying Flink on Kubernetes - David Anderson
Ververica
 

Similar to Hazelcast Distributed Lock (20)

PPTX
Hazelcast sunum
Software Infrastructure
 
PPTX
Training Webinar: Enterprise application performance with distributed caching
OutSystems
 
PDF
Hazelcast 101
Emrah Kocaman
 
PDF
Support distributed computing and caching avec hazelcast
ENSET, Université Hassan II Casablanca
 
PPTX
From cache to in-memory data grid. Introduction to Hazelcast.
Taras Matyashovsky
 
PDF
AEM - Binary less replication
Ashokkumar T A
 
PDF
Internet Facing VMs and the DDoS Problem, Wido den Hollander, Your.Online
ShapeBlue
 
PPTX
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
DataStax
 
PDF
CloudStack - LinuxFest NorthWest
ke4qqq
 
PPT
Hazelcast
Jeevesh Pandey
 
PDF
Where Django Caching Bust at the Seams
Concentric Sky
 
PPTX
Preparing for Multi-Cloud
Konstantin Tjuterev
 
PDF
Data has a better idea the in-memory data grid
Bogdan Dina
 
PDF
Caching and JCache with Greg Luck 18.02.16
Comsysto Reply GmbH
 
ODP
Clustering In The Wild
Sergio Bossa
 
PDF
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Haribabu Nandyal Padmanaban
 
PPTX
Mini-Training: To cache or not to cache
Betclic Everest Group Tech Team
 
PPTX
[Hanoi-August 13] Tech Talk on Caching Solutions
ITviec
 
PDF
Mysql wp memcached
sharad chhetri
 
PDF
The State of Rootless Containers
Akihiro Suda
 
Hazelcast sunum
Software Infrastructure
 
Training Webinar: Enterprise application performance with distributed caching
OutSystems
 
Hazelcast 101
Emrah Kocaman
 
Support distributed computing and caching avec hazelcast
ENSET, Université Hassan II Casablanca
 
From cache to in-memory data grid. Introduction to Hazelcast.
Taras Matyashovsky
 
AEM - Binary less replication
Ashokkumar T A
 
Internet Facing VMs and the DDoS Problem, Wido den Hollander, Your.Online
ShapeBlue
 
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
DataStax
 
CloudStack - LinuxFest NorthWest
ke4qqq
 
Hazelcast
Jeevesh Pandey
 
Where Django Caching Bust at the Seams
Concentric Sky
 
Preparing for Multi-Cloud
Konstantin Tjuterev
 
Data has a better idea the in-memory data grid
Bogdan Dina
 
Caching and JCache with Greg Luck 18.02.16
Comsysto Reply GmbH
 
Clustering In The Wild
Sergio Bossa
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Haribabu Nandyal Padmanaban
 
Mini-Training: To cache or not to cache
Betclic Everest Group Tech Team
 
[Hanoi-August 13] Tech Talk on Caching Solutions
ITviec
 
Mysql wp memcached
sharad chhetri
 
The State of Rootless Containers
Akihiro Suda
 
Ad

More from Jadson Santos (19)

PDF
A Deep Dive into Continuous Integration Monitoring Practices
Jadson Santos
 
PDF
Containerizing a Web Application with Vue.js and Java
Jadson Santos
 
PPTX
Continuous Delivery with Jenkins
Jadson Santos
 
PPTX
Cd with Github Travis CI and Heroku
Jadson Santos
 
PDF
Vue.js
Jadson Santos
 
PDF
Jenkins Continuous Delivery
Jadson Santos
 
PPTX
Introduction to angular with a simple but complete project
Jadson Santos
 
PDF
Bootstrap
Jadson Santos
 
PPTX
Testes Unitários
Jadson Santos
 
PPTX
Java8
Jadson Santos
 
PPTX
Gradle
Jadson Santos
 
PPTX
Git
Jadson Santos
 
PDF
Introdução ao Flyway
Jadson Santos
 
PDF
Mini curso gerenciamento de configuração e mudança com GIT + Eclipse - I...
Jadson Santos
 
PDF
Usando hiberante de forma otimizada
Jadson Santos
 
PDF
Usando JMeter para testar sua aplicação JSF
Jadson Santos
 
PDF
ICEIS 2013 Presentation
Jadson Santos
 
PDF
Enums
Jadson Santos
 
PDF
Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...
Jadson Santos
 
A Deep Dive into Continuous Integration Monitoring Practices
Jadson Santos
 
Containerizing a Web Application with Vue.js and Java
Jadson Santos
 
Continuous Delivery with Jenkins
Jadson Santos
 
Cd with Github Travis CI and Heroku
Jadson Santos
 
Jenkins Continuous Delivery
Jadson Santos
 
Introduction to angular with a simple but complete project
Jadson Santos
 
Bootstrap
Jadson Santos
 
Testes Unitários
Jadson Santos
 
Introdução ao Flyway
Jadson Santos
 
Mini curso gerenciamento de configuração e mudança com GIT + Eclipse - I...
Jadson Santos
 
Usando hiberante de forma otimizada
Jadson Santos
 
Usando JMeter para testar sua aplicação JSF
Jadson Santos
 
ICEIS 2013 Presentation
Jadson Santos
 
Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...
Jadson Santos
 
Ad

Recently uploaded (20)

PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Digital Circuits, important subject in CS
contactparinay1
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 

Hazelcast Distributed Lock

  • 2. Problem • Some times you need a critical region in your system where 2 threads can not access this part of code concurrently, or something wrong will happen • • The easiest way to do this, is used the Java synchronized block: 20/03/17 Hazelcast distributed lock
  • 3. Problem • The problem with this approach is that it just work in the same Java Virtual Machine. • • What can we do if we have several instances of our application running? • 20/03/17 Hazelcast distributed lock
  • 4. DataBase Distributed Lock • The first option is use database based lock • • With Hibernate we have something like this: • 20/03/17 Hazelcast distributed lock
  • 5. DataBase Distributed Lock • If two threads call the findObjectLock method at same time, the second one you will wait until the first transaction is closed. • • But if we have several databases or we can not use the lock of the database? • 20/03/17 Hazelcast distributed lock
  • 6. HazelCast Distributed Lock • The Hazelcast IMDG operational in-memory computing platform helps leading companies worldwide manage their data and distribute processing using in-memory storage and parallel execution for breakthrough application speed and scale [1]. • • Hazelcast implement a distributed version of some Java data structures like Maps, Set, Lists, Queue and Lock • 20/03/17 Hazelcast distributed lock
  • 7. HazelCast Distributed Lock • ILock is the distributed implementation of java.util.concurrent.locks.Lock. Meaning if you lock using an ILock, the critical section that it guards is guaranteed to be executed by only one thread in the entire cluster [2]. • 20/03/17 Hazelcast distributed lock
  • 8. Configuring HazelCast • Just add a simple Jar to the application classpath. • • With Gradle stay like this: • 20/03/17 Hazelcast distributed lock
  • 9. Configuring HazelCast Cluster • Programmatically you need initiated a Config object for the HazelCast instance • • • • • • First of all, we choose the cluster initial port number and the number of ports the cluster we use. • • If you have several threads at same time access the cluster, it is necessary have several ports • 20/03/17 Hazelcast distributed lock
  • 10. Configuring HazelCast Cluster • After that, we need to chose if use Multicast or specific IPs addresses in the cluster, we configure to use specific IPs • • • • • • • 20/03/17 Hazelcast distributed lock
  • 11. Configuring HazelCast Cluster • Now we inform these specific IPs to the cluster • • • • • • • 20/03/17 Hazelcast distributed lock
  • 12. Configuring HazelCast Cluster • At last, we specify which network interfaces that Hazelcast should use • • • • • • • 20/03/17 Hazelcast distributed lock
  • 13. Configuring HazelCast Cluster • We can now instantiate a new Hazelcast Instance with this configuration, how iniciate a Hazelcast instance is slow, takes around 3 seconds, we initialized just one instance per JVM 20/03/17 Hazelcast distributed lock
  • 14. Configuring HazelCast Cluster • The complete code: 20/03/17 Hazelcast distributed lock
  • 15. Using HazelCast Cluster • You must call HazelCast lock in a try-finally block to ensure that the lock will be release. • The lock have an identifier, so we can have different locks in the same cluster 20/03/17 Hazelcast distributed lock
  • 16. References • [1] Hazelcast IMDG. The Leading Open Source In- Memory Data Grid. https://hazelcast.org/ • • [2] Lock http://docs.hazelcast.org/docs/3.5/manual/html/lock.html 20/03/17 Hazelcast distributed lock