{"id":24448594,"url":"https://github.com/hellooo-stack/halo-distributedlock","last_synced_at":"2026-04-12T22:06:05.362Z","repository":{"id":49364240,"uuid":"515244911","full_name":"hellooo-stack/halo-distributedlock","owner":"hellooo-stack","description":"A simple but reliable distributed lock implementation","archived":false,"fork":false,"pushed_at":"2023-10-11T02:34:16.000Z","size":93,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-14T05:42:12.977Z","etag":null,"topics":["distributed-lock","java","redis"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hellooo-stack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-18T15:41:53.000Z","updated_at":"2023-09-28T02:43:15.000Z","dependencies_parsed_at":"2025-01-21T00:32:25.071Z","dependency_job_id":"b8b1d4dd-c944-475c-938e-6d9aee0b7e67","html_url":"https://github.com/hellooo-stack/halo-distributedlock","commit_stats":null,"previous_names":["hellooo-stack/halo-distributedlock"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/hellooo-stack/halo-distributedlock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellooo-stack%2Fhalo-distributedlock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellooo-stack%2Fhalo-distributedlock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellooo-stack%2Fhalo-distributedlock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellooo-stack%2Fhalo-distributedlock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hellooo-stack","download_url":"https://codeload.github.com/hellooo-stack/halo-distributedlock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellooo-stack%2Fhalo-distributedlock/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260281568,"owners_count":22985629,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distributed-lock","java","redis"],"created_at":"2025-01-21T00:32:12.476Z","updated_at":"2025-10-30T03:55:22.244Z","avatar_url":"https://github.com/hellooo-stack.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Halo-DistributedLock\n\n![Build](https://img.shields.io/github/actions/workflow/status/hellooo-stack/halo-distributedlock/maven.yml)\n![Code Size](https://img.shields.io/github/languages/code-size/hellooo-stack/halo-distributedlock)\n![Maven Central](https://img.shields.io/maven-central/v/site.hellooo/halo-distributedlock-core)\n![GitHub license](https://img.shields.io/github/license/hellooo-stack/halo-distributedlock)\n\nhalo-distributedlock is a simple and reliable distributed lock implementation. \nIt is designed to help you learn the principles of distributed locking \nand provides a lightweight solution for your production environment (assuming you are using single instance Redis). \nWhether you're a beginner or an experienced developer, It's worth to take a look at.\n\n# Features\n- Supports distributed lock, distributed unlock operations with a singleton Redis.\n- Supports lock leasing, lock blocking and lock reentrant.\n\n# Quick Start\nStep one: Add maven dependency\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003esite.hellooo\u003c/groupId\u003e\n    \u003cartifactId\u003ehalo-distributedlock-core\u003c/artifactId\u003e\n    \u003cversion\u003e\u003e${halo-distributedlock.version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nStep two: lock your resources with Lock.lock()\n```java\npublic class SingleProcessMultiThreadContention {\n    public static void main(String[] args) {\n        lockCompetition();\n    }\n\n    public static void lockCompetition() {\n        long start = System.currentTimeMillis();\n\n        ConfigReader.RedisConfig redisConfig = ConfigReader.redis();\n        String host = redisConfig.getHost();\n        int port = redisConfig.getPort();\n\n        JedisPool jedisPool = new JedisPool(host, port);\n        for (int i = 0; i \u003c 500; i++) {\n            final int threadNumber = i;\n            Thread thread = new Thread(() -\u003e {\n                Thread.currentThread().setName(\"locking_thread_\" + threadNumber);\n\n                Lock lock = new ReentrantDistributedLockBuilder()\n                        .lockOptions(LockOptions.ofDefault())\n                        .jedisPool(jedisPool)\n                        .lockTarget(\"my_lock\")\n                        .build();\n\n                System.out.println(\"process [\" + ProcessUtils.getProcessId() + \"] thread [\" + Thread.currentThread().getName() + \"] is getting lock\");\n                lock.lock();\n                System.out.println(\"process [\" + ProcessUtils.getProcessId() + \"] thread [\" + Thread.currentThread().getName() + \"] got lock\");\n                lock.unlock();\n                System.out.println(\"process [\" + ProcessUtils.getProcessId() + \"] thread [\" + Thread.currentThread().getName() + \"] released lock\");\n            });\n            thread.start();\n        }\n\n        Runtime.getRuntime().addShutdownHook(new Thread(() -\u003e {\n            jedisPool.close();\n            System.out.println(\"cause: \" + (System.currentTimeMillis() - start) + \"ms\");\n        }));\n    }\n}\n```\n\n# Examples\nYou can find some examples in the [examples](https://github.com/hellooo-stack/halo-distributedlock/tree/master/examples) module. \nIf you want to simulate multiple-process, multiple-thread competition, you should run multiprocess/Step0, \nand then run multiprocess/Step1 within a 5-second window. You will see the result like this:\n```\n# process1:\n# process [99991] thread [locking_thread_0] is getting lock\n# process [99991] thread [locking_thread_8] is getting lock\n# process [99991] thread [locking_thread_7] is getting lock\n# process [99991] thread [locking_thread_6] is getting lock\n# process [99991] thread [locking_thread_2] is getting lock\n# process [99991] thread [locking_thread_5] is getting lock\n# process [99991] thread [locking_thread_4] is getting lock\n# process [99991] thread [locking_thread_3] is getting lock\n# process [99991] thread [locking_thread_9] is getting lock\n# process [99991] thread [locking_thread_1] is getting lock\n# process [99991] thread [locking_thread_8] got lock\n# process [99991] thread [locking_thread_8] released lock\n# process [99991] thread [locking_thread_7] got lock\n# process [99991] thread [locking_thread_7] released lock\n# process [99991] thread [locking_thread_3] got lock\n# process [99991] thread [locking_thread_3] released lock\n# process [99991] thread [locking_thread_0] got lock\n# process [99991] thread [locking_thread_0] released lock\n# process [99991] thread [locking_thread_9] got lock\n# process [99991] thread [locking_thread_9] released lock\n# process [99991] thread [locking_thread_2] got lock\n# process [99991] thread [locking_thread_2] released lock\n# ...\n\n\n# process2:\n# process [96469] thread [locking_thread_498] is getting lock\n# process [96469] thread [locking_thread_499] is getting lock\n# process [96469] thread [locking_thread_152] got lock\n# process [96469] thread [locking_thread_152] released lock\n# process [96469] thread [locking_thread_139] got lock\n# process [96469] thread [locking_thread_139] released lock\n# process [96469] thread [locking_thread_417] got lock\n# process [96469] thread [locking_thread_417] released lock\n# process [96469] thread [locking_thread_213] got lock\n# process [96469] thread [locking_thread_213] released lock\n# process [96469] thread [locking_thread_458] got lock\n# process [96469] thread [locking_thread_458] released lock\n# process [96469] thread [locking_thread_124] got lock\n# process [96469] thread [locking_thread_124] released lock\n# process [96469] thread [locking_thread_204] got lock\n# process [96469] thread [locking_thread_204] released lock\n# ...\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellooo-stack%2Fhalo-distributedlock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhellooo-stack%2Fhalo-distributedlock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellooo-stack%2Fhalo-distributedlock/lists"}