[Feature] add for new

This commit is contained in:
houbb
2020-10-19 23:38:19 +08:00
parent 67f8b1e2a7
commit 56e25d67e3
10 changed files with 645 additions and 16 deletions

View File

@@ -1,7 +1,10 @@
package com.github.houbb.lock.test.core;
import com.github.houbb.heaven.util.util.DateUtil;
import com.github.houbb.lock.api.core.ILock;
import com.github.houbb.lock.redis.core.LockWaitNotify;
import com.github.houbb.log.integration.core.Log;
import com.github.houbb.log.integration.core.LogFactory;
import java.util.concurrent.TimeUnit;
@@ -11,26 +14,19 @@ import java.util.concurrent.TimeUnit;
*/
public class LockWaitNotifyThread implements Runnable {
private static final Log log = LogFactory.getLog(LockWaitNotifyThread.class);
private final ILock lock = new LockWaitNotify();
@Override
public void run() {
System.out.println("first-lock: " + Thread.currentThread().getId());
log.debug("first lock");
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();
}
log.info("执行业务逻辑。");
DateUtil.sleep(TimeUnit.SECONDS, 5);
lock.unlock();
System.out.println("first-unlock: " + Thread.currentThread().getId());
log.debug("first unlock");
}
public static void main(String[] args) {

View File

@@ -0,0 +1,45 @@
package com.github.houbb.lock.test.core;
import com.github.houbb.heaven.util.util.DateUtil;
import com.github.houbb.lock.api.core.ILock;
import com.github.houbb.lock.redis.core.LockWaitNotify;
import com.github.houbb.log.integration.core.Log;
import com.github.houbb.log.integration.core.LogFactory;
import java.util.concurrent.TimeUnit;
/**
* @author binbin.hou
* @since 1.0.0
*/
public class LockWaitNotifyThread2 implements Runnable {
private static final Log log = LogFactory.getLog(LockWaitNotifyThread2.class);
private final ILock lock = new LockWaitNotify();
@Override
public void run() {
log.debug("first lock");
lock.lock();
log.debug("second lock");
lock.lock();
log.info("执行业务逻辑。");
DateUtil.sleep(TimeUnit.SECONDS, 5);
log.debug("second unlock");
lock.unlock();
lock.unlock();
log.debug("first unlock");
}
public static void main(String[] args) {
final Runnable runnable = new LockWaitNotifyThread2();
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.heaven.util.util.DateUtil;
import com.github.houbb.lock.api.core.ILock;
import com.github.houbb.lock.redis.core.LockWaitNotify;
import com.github.houbb.lock.redis.core.LockWaitNotifyRe;
import com.github.houbb.log.integration.core.Log;
import com.github.houbb.log.integration.core.LogFactory;
import java.util.concurrent.TimeUnit;
/**
* @author binbin.hou
* @since 1.0.0
*/
public class LockWaitNotifyThreadRe implements Runnable {
private static final Log log = LogFactory.getLog(LockWaitNotifyThreadRe.class);
private final ILock lock = new LockWaitNotifyRe();
@Override
public void run() {
log.debug("first lock");
lock.lock();
log.debug("second lock");
lock.lock();
log.debug("second unlock");
lock.unlock();
log.debug("first unlock");
lock.unlock();
}
public static void main(String[] args) {
final Runnable runnable = new LockWaitNotifyThreadRe();
new Thread(runnable).start();
new Thread(runnable).start();
new Thread(runnable).start();
}
}