[Feature] add for new

This commit is contained in:
binbin.hou
2020-10-19 18:23:20 +08:00
parent acbd8f4022
commit 67f8b1e2a7
11 changed files with 329 additions and 6 deletions

View File

@@ -0,0 +1,36 @@
package com.github.houbb.lock.test.core;
import com.github.houbb.lock.api.core.ILock;
import com.github.houbb.lock.redis.core.LockSpin;
import com.github.houbb.lock.redis.core.LockSpinRe;
/**
* @author binbin.hou
* @since 1.0.0
*/
public class LockSpinReThread implements Runnable {
private final ILock lock = new LockSpinRe();
@Override
public void run() {
System.out.println("first-lock: " + Thread.currentThread().getId());
lock.lock();
System.out.println("second-lock: " + Thread.currentThread().getId());
lock.lock();
lock.unlock();
System.out.println("second-unlock: " + Thread.currentThread().getId());
lock.unlock();
System.out.println("first-unlock: " + Thread.currentThread().getId());
}
public static void main(String[] args) {
final Runnable runnable = new LockSpinReThread();
new Thread(runnable).start();
new Thread(runnable).start();
new Thread(runnable).start();
}
}

View File

@@ -0,0 +1,35 @@
package com.github.houbb.lock.test.core;
import com.github.houbb.lock.api.core.ILock;
import com.github.houbb.lock.redis.core.LockSpin;
/**
* @author binbin.hou
* @since 1.0.0
*/
public class LockSpinThread implements Runnable {
private final ILock lock = new LockSpin();
@Override
public void run() {
System.out.println("first-lock: " + Thread.currentThread().getId());
lock.lock();
System.out.println("second-lock: " + Thread.currentThread().getId());
lock.lock();
lock.unlock();
System.out.println("second-unlock: " + Thread.currentThread().getId());
lock.unlock();
System.out.println("first-unlock: " + Thread.currentThread().getId());
}
public static void main(String[] args) {
final Runnable runnable = new LockSpinThread();
new Thread(runnable).start();
new Thread(runnable).start();
new Thread(runnable).start();
}
}

View File

@@ -0,0 +1,43 @@
package com.github.houbb.lock.test.core;
import com.github.houbb.lock.api.core.ILock;
import com.github.houbb.lock.redis.core.LockWaitNotify;
import java.util.concurrent.TimeUnit;
/**
* @author binbin.hou
* @since 1.0.0
*/
public class LockWaitNotifyThread implements Runnable {
private final ILock lock = new LockWaitNotify();
@Override
public void run() {
System.out.println("first-lock: " + Thread.currentThread().getId());
lock.lock();
// System.out.println("second-lock: " + Thread.currentThread().getId());
// lock.lock();
// lock.unlock();
// System.out.println("second-unlock: " + Thread.currentThread().getId());
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
lock.unlock();
System.out.println("first-unlock: " + Thread.currentThread().getId());
}
public static void main(String[] args) {
final Runnable runnable = new LockWaitNotifyThread();
new Thread(runnable).start();
new Thread(runnable).start();
new Thread(runnable).start();
}
}

View File

@@ -11,7 +11,7 @@ import redis.clients.jedis.Jedis;
* @author binbin.hou
* @since 0.0.1
*/
public class RedisLockTest {
public class LockRedisTest {
@Test
public void helloTest() {