SlideShare a Scribd company logo
1 of 16
Download to read offline
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

Lessons learned from running Spark on Docker
Lessons learned from running Spark on DockerLessons learned from running Spark on Docker
Lessons learned from running Spark on Docker
DataWorks Summit
 

What's hot (20)

Rainbird: Realtime Analytics at Twitter (Strata 2011)
Rainbird: Realtime Analytics at Twitter (Strata 2011)Rainbird: Realtime Analytics at Twitter (Strata 2011)
Rainbird: Realtime Analytics at Twitter (Strata 2011)
 
Cloud arch patterns
Cloud arch patternsCloud arch patterns
Cloud arch patterns
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafka
 
Distributed Lock Manager
Distributed Lock ManagerDistributed Lock Manager
Distributed Lock Manager
 
Performance Monitoring: Understanding Your Scylla Cluster
Performance Monitoring: Understanding Your Scylla ClusterPerformance Monitoring: Understanding Your Scylla Cluster
Performance Monitoring: Understanding Your Scylla Cluster
 
Tame the small files problem and optimize data layout for streaming ingestion...
Tame the small files problem and optimize data layout for streaming ingestion...Tame the small files problem and optimize data layout for streaming ingestion...
Tame the small files problem and optimize data layout for streaming ingestion...
 
Rds data lake @ Robinhood
Rds data lake @ Robinhood Rds data lake @ Robinhood
Rds data lake @ Robinhood
 
Kafka High Availability in multi data center setup with floating Observers wi...
Kafka High Availability in multi data center setup with floating Observers wi...Kafka High Availability in multi data center setup with floating Observers wi...
Kafka High Availability in multi data center setup with floating Observers wi...
 
HBaseCon 2015: HBase Performance Tuning @ Salesforce
HBaseCon 2015: HBase Performance Tuning @ SalesforceHBaseCon 2015: HBase Performance Tuning @ Salesforce
HBaseCon 2015: HBase Performance Tuning @ Salesforce
 
Deletes Without Tombstones or TTLs (Eric Stevens, ProtectWise) | Cassandra Su...
Deletes Without Tombstones or TTLs (Eric Stevens, ProtectWise) | Cassandra Su...Deletes Without Tombstones or TTLs (Eric Stevens, ProtectWise) | Cassandra Su...
Deletes Without Tombstones or TTLs (Eric Stevens, ProtectWise) | Cassandra Su...
 
Deep Dive into Apache Kafka
Deep Dive into Apache KafkaDeep Dive into Apache Kafka
Deep Dive into Apache Kafka
 
Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021
Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021
Building ClickHouse and Making Your First Contribution: A Tutorial_06.10.2021
 
Lessons learned from running Spark on Docker
Lessons learned from running Spark on DockerLessons learned from running Spark on Docker
Lessons learned from running Spark on Docker
 
Performance Tuning RocksDB for Kafka Streams' State Stores (Dhruba Borthakur,...
Performance Tuning RocksDB for Kafka Streams' State Stores (Dhruba Borthakur,...Performance Tuning RocksDB for Kafka Streams' State Stores (Dhruba Borthakur,...
Performance Tuning RocksDB for Kafka Streams' State Stores (Dhruba Borthakur,...
 
Building Stream Infrastructure across Multiple Data Centers with Apache Kafka
Building Stream Infrastructure across Multiple Data Centers with Apache KafkaBuilding Stream Infrastructure across Multiple Data Centers with Apache Kafka
Building Stream Infrastructure across Multiple Data Centers with Apache Kafka
 
Optimizing Hive Queries
Optimizing Hive QueriesOptimizing Hive Queries
Optimizing Hive Queries
 
Apache Kafka - Martin Podval
Apache Kafka - Martin PodvalApache Kafka - Martin Podval
Apache Kafka - Martin Podval
 
Extending Flink SQL for stream processing use cases
Extending Flink SQL for stream processing use casesExtending Flink SQL for stream processing use cases
Extending Flink SQL for stream processing use cases
 
Kafka Streams State Stores Being Persistent
Kafka Streams State Stores Being PersistentKafka Streams State Stores Being Persistent
Kafka Streams State Stores Being Persistent
 
Demystifying flink memory allocation and tuning - Roshan Naik, Uber
Demystifying flink memory allocation and tuning - Roshan Naik, UberDemystifying flink memory allocation and tuning - Roshan Naik, Uber
Demystifying flink memory allocation and tuning - Roshan Naik, Uber
 

Similar to Hazelcast Distributed Lock

What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
DataStax
 
CloudStack - LinuxFest NorthWest
CloudStack - LinuxFest NorthWestCloudStack - LinuxFest NorthWest
CloudStack - LinuxFest NorthWest
ke4qqq
 
Clustering In The Wild
Clustering In The WildClustering In The Wild
Clustering In The Wild
Sergio Bossa
 

Similar to Hazelcast Distributed Lock (20)

Hazelcast sunum
Hazelcast sunumHazelcast sunum
Hazelcast sunum
 
Training Webinar: Enterprise application performance with distributed caching
Training Webinar: Enterprise application performance with distributed cachingTraining Webinar: Enterprise application performance with distributed caching
Training Webinar: Enterprise application performance with distributed caching
 
Hazelcast 101
Hazelcast 101Hazelcast 101
Hazelcast 101
 
Support distributed computing and caching avec hazelcast
Support distributed computing and caching avec hazelcastSupport distributed computing and caching avec hazelcast
Support distributed computing and caching avec hazelcast
 
From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.
 
AEM - Binary less replication
AEM - Binary less replicationAEM - Binary less replication
AEM - Binary less replication
 
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
What We Learned About Cassandra While Building go90 (Christopher Webster & Th...
 
CloudStack - LinuxFest NorthWest
CloudStack - LinuxFest NorthWestCloudStack - LinuxFest NorthWest
CloudStack - LinuxFest NorthWest
 
Hazelcast
HazelcastHazelcast
Hazelcast
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the Seams
 
Preparing for Multi-Cloud
Preparing for Multi-CloudPreparing for Multi-Cloud
Preparing for Multi-Cloud
 
Data has a better idea the in-memory data grid
Data has a better idea   the in-memory data gridData has a better idea   the in-memory data grid
Data has a better idea the in-memory data grid
 
Caching and JCache with Greg Luck 18.02.16
Caching and JCache with Greg Luck 18.02.16Caching and JCache with Greg Luck 18.02.16
Caching and JCache with Greg Luck 18.02.16
 
Clustering In The Wild
Clustering In The WildClustering In The Wild
Clustering In The Wild
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
 
Mini-Training: To cache or not to cache
Mini-Training: To cache or not to cacheMini-Training: To cache or not to cache
Mini-Training: To cache or not to cache
 
[Hanoi-August 13] Tech Talk on Caching Solutions
[Hanoi-August 13] Tech Talk on Caching Solutions[Hanoi-August 13] Tech Talk on Caching Solutions
[Hanoi-August 13] Tech Talk on Caching Solutions
 
Mysql wp memcached
Mysql wp memcachedMysql wp memcached
Mysql wp memcached
 
The State of Rootless Containers
The State of Rootless ContainersThe State of Rootless Containers
The State of Rootless Containers
 
Elastic Migration 2.x to 6.x By Pankaj Gajjar
Elastic Migration 2.x to 6.x By Pankaj GajjarElastic Migration 2.x to 6.x By Pankaj Gajjar
Elastic Migration 2.x to 6.x By Pankaj Gajjar
 

More from Jadson Santos

A Deep Dive into Continuous Integration Monitoring Practices
A Deep Dive into Continuous Integration Monitoring PracticesA Deep Dive into Continuous Integration Monitoring Practices
A Deep Dive into Continuous Integration Monitoring Practices
Jadson Santos
 
Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...
Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...
Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...
Jadson Santos
 

More from Jadson Santos (19)

A Deep Dive into Continuous Integration Monitoring Practices
A Deep Dive into Continuous Integration Monitoring PracticesA Deep Dive into Continuous Integration Monitoring Practices
A Deep Dive into Continuous Integration Monitoring Practices
 
Containerizing a Web Application with Vue.js and Java
Containerizing a Web Application with Vue.js and JavaContainerizing a Web Application with Vue.js and Java
Containerizing a Web Application with Vue.js and Java
 
Continuous Delivery with Jenkins
Continuous Delivery with JenkinsContinuous Delivery with Jenkins
Continuous Delivery with Jenkins
 
Cd with Github Travis CI and Heroku
Cd with Github Travis CI and HerokuCd with Github Travis CI and Heroku
Cd with Github Travis CI and Heroku
 
Vue.js
Vue.jsVue.js
Vue.js
 
Jenkins Continuous Delivery
Jenkins Continuous DeliveryJenkins Continuous Delivery
Jenkins Continuous Delivery
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
Testes Unitários
Testes UnitáriosTestes Unitários
Testes Unitários
 
Java8
Java8Java8
Java8
 
Gradle
GradleGradle
Gradle
 
Git
GitGit
Git
 
Introdução ao Flyway
Introdução ao FlywayIntrodução ao Flyway
Introdução ao Flyway
 
Mini curso gerenciamento de configuração e mudança com GIT + Eclipse - I...
Mini curso gerenciamento de configuração e mudança com GIT + Eclipse  -  I...Mini curso gerenciamento de configuração e mudança com GIT + Eclipse  -  I...
Mini curso gerenciamento de configuração e mudança com GIT + Eclipse - I...
 
Usando hiberante de forma otimizada
Usando hiberante de forma otimizadaUsando hiberante de forma otimizada
Usando hiberante de forma otimizada
 
Usando JMeter para testar sua aplicação JSF
Usando JMeter para testar sua aplicação JSFUsando JMeter para testar sua aplicação JSF
Usando JMeter para testar sua aplicação JSF
 
ICEIS 2013 Presentation
ICEIS 2013 PresentationICEIS 2013 Presentation
ICEIS 2013 Presentation
 
Enums
EnumsEnums
Enums
 
Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...
Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...
Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

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