check方法加锁
This commit is contained in:
@@ -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("一个链接检查未通过");
|
||||
|
||||
Reference in New Issue
Block a user