-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
153 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
4 changes: 4 additions & 0 deletions
4
...rc/main/java/site/hellooo/distributedlock/examples/MultiProcessMultiThreadContention.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package site.hellooo.distributedlock.examples; | ||
|
||
public class MultiProcessMultiThreadContention { | ||
} |
41 changes: 41 additions & 0 deletions
41
...c/main/java/site/hellooo/distributedlock/examples/SingleProcessMultiThreadContention.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters