Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Alpha2J committed Oct 10, 2023
1 parent 0ee512d commit e3c36a9
Show file tree
Hide file tree
Showing 44 changed files with 153 additions and 35 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Hi there! We're thrilled that you'd like to contribute to this project. Your hel

## Submitting a pull request

1. [Fork][fork] and clone the repository
1. Fork and clone the repository
2. Create a new branch: `git checkout -b my-branch-name`
3. Make your change and remember to add tests
4. Build the project locally and run local tests
5. Push to your fork and [submit a pull request][pr]
5. Push to your fork and submit a pull request
6. Pat your self on the back and wait for your pull request to be reviewed and merged.

Thanks for your contributing!
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,12 @@ public class Main {
}

```



you can use it for study, or in your production environment if it met your requirement which is only single redis instance needed.
it is not recommended to use it in production environment if you need high availability, because it is not support redis cluster yet.

jdk: 1.8


32 changes: 32 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>site.hellooo</groupId>
<artifactId>halo-distributedlock</artifactId>
<version>${revision}</version>
</parent>

<artifactId>halo-distributedlock-core</artifactId>

<dependencies>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>
</project>
21 changes: 21 additions & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>site.hellooo</groupId>
<artifactId>halo-distributedlock</artifactId>
<version>${revision}</version>
</parent>

<artifactId>halo-distributedlock-examples</artifactId>

<dependencies>
<dependency>
<groupId>site.hellooo</groupId>
<artifactId>halo-distributedlock-core</artifactId>
<version>0.0.7-GA</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package site.hellooo.distributedlock.examples;

public class MultiProcessMultiThreadContention {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package site.hellooo.distributedlock.examples;

import redis.clients.jedis.JedisPool;
import site.hellooo.distributedlock.config.LockOptions;
import site.hellooo.distributedlock.impl.ReentrantDistributedLock;
import site.hellooo.distributedlock.impl.redis.RedisLockHandler;

import java.util.concurrent.locks.Lock;

public class SingleProcessMultiThreadContention {
public static void main(String[] args) {
LockOptions lockOptions = LockOptions.options()
.build();

// define the redis source
JedisPool pool = new JedisPool("localhost", 6379);
for (int i = 0; i < 1000; i++) {
final int threadNumber = i;
Thread thread = new Thread(() -> {
Thread.currentThread().setName("Thread " + threadNumber);
// Thread.sleep(1);
// String world = jedis.get("hello");
// System.out.println("world= " + world);
try {
Lock lock = new ReentrantDistributedLock(lockOptions, "my_lock", new RedisLockHandler(pool));
// lock
lock.lock();
System.out.println("thread" + Thread.currentThread().getName() + " locked!");
// Thread.sleep(1000);
System.out.println("thread" + Thread.currentThread().getName() + " lock released!");
// unlock
lock.unlock();
System.out.println("after thread" + Thread.currentThread().getName() + " lock released!");
} catch (Exception e) {
e.printStackTrace();
}
});
thread.start();
}
}
}
77 changes: 44 additions & 33 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,56 @@

<groupId>site.hellooo</groupId>
<artifactId>halo-distributedlock</artifactId>
<version>0.0.6-GA</version>
<version>${revision}</version>
<packaging>pom</packaging>
<modules>
<module>core</module>
</modules>

<properties>
<revision>0.0.7-GA</revision>

<project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>

<jedis.version>4.2.3</jedis.version>
<junit.version>4.13.2</junit.version>
<assertj-core.version>3.23.1</assertj-core.version>
<mockito-core.version>4.6.1</mockito-core.version>
</properties>
<dependencies>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>${junit.version}</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito-core.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<!-- 发布maven中央仓库所需数据 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito-core.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

<!-- metadata required for publishing to maven central repository -->
<name>distributed-lock</name>
<description>a simple but reliable distributed lock implementation</description>
<url>https://github.com/hellooo-stack/halo-distributedlock</url>
Expand All @@ -66,7 +77,7 @@
</developers>
<distributionManagement>
<snapshotRepository>
<!-- 对应settings.xml内配置的<server>下的id -->
<!-- the identifier corresponding to the <server> element in the settings.xml configuration -->
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
Expand All @@ -80,7 +91,7 @@
<id>release</id>
<build>
<plugins>
<!-- 生成源码 jar -->
<!-- creating a jar for sourcecode -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand All @@ -94,7 +105,7 @@
</execution>
</executions>
</plugin>
<!-- 生成javadoc jar -->
<!-- creating a doc jar for sourcecode -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
Expand All @@ -108,7 +119,7 @@
</execution>
</executions>
</plugin>
<!-- gpg 签名 -->
<!-- gpg signature -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
Expand All @@ -123,7 +134,7 @@
</execution>
</executions>
</plugin>
<!-- nexus 组件发布 -->
<!-- nexus component publishing -->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
Expand Down

0 comments on commit e3c36a9

Please sign in to comment.