check方法加锁

This commit is contained in:
junj2.liang
2022-08-15 15:39:01 +08:00
parent 5243ec1fe1
commit 24335ccd95
2 changed files with 39 additions and 32 deletions
@@ -12,6 +12,8 @@ import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class ThreadBasedConnectPool<T> {
static {
@@ -28,6 +30,7 @@ public class ThreadBasedConnectPool<T> {
private PoolConfig config;
public ThreadBasedConnectPool(PoolConfig config) {
Lock l = new ReentrantLock();
this.config = config;
threadPool.scheduleAtFixedRate(new Runnable() {
@Override
@@ -62,10 +65,14 @@ public class ThreadBasedConnectPool<T> {
boolean checkRet = false;
try {
l.lock();
checkRet = check(entry.getValue().getObject());
} catch (Exception e) {
checkRet = false;
}
finally {
l.unlock();
}
if (checkRet) {
log.debug("一个链接检查未通过");