Skip to content

abhirockzz/apache-curator-distributed-lock

Repository files navigation

Distributed/interprocess mutexes/locks using Apache Curator

For details, read the blog. Run two instances of each process (one after the other in quick succession) to observe the behavior

Behavior

In the block for lock test

  • for both the processes that run the task, the for loop will be executed twice
  • this is because of the blocking/queuing effect - the thread in each process will wait until the lock is released by the thread in another process (this will happen for both iterations of the loop)

Block for Lock

In the non-blocking request for the lock test

  • the thread wait time for work simulation (3 seconds) has been kept lower than the lock acquire time out (2 seconds) on purpose
  • for both the processes, only one iteration of the loop in the task is executed (either first or second)
  • this is because the thread in the process which fails to get the lock does not block - it simply returns and repeats the loop (hence misses that iteration of task/job)

Non block lock

Note

Please change the Zookeeper instance details before testing things out - here and here

About

Explore distributed locks using InterProcessMutex in Apache Curator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages