From 4cb88a0f74e2ea22a933bdc166558684365a5810 Mon Sep 17 00:00:00 2001 From: ZhangZiSheng001 <18826241741@163.com> Date: Wed, 8 Apr 2020 08:41:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9JDBCUtils=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/cn/zzs/dbcp/JDBCUtils.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/cn/zzs/dbcp/JDBCUtils.java b/src/main/java/cn/zzs/dbcp/JDBCUtils.java index ca87898..a65d481 100644 --- a/src/main/java/cn/zzs/dbcp/JDBCUtils.java +++ b/src/main/java/cn/zzs/dbcp/JDBCUtils.java @@ -24,8 +24,6 @@ public class JDBCUtils { private static ThreadLocal tl = new ThreadLocal<>(); - private static final Object obj = new Object(); - private static final Log log = LogFactory.getLog(JDBCUtils.class); static { @@ -44,12 +42,8 @@ public class JDBCUtils { Connection connection = tl.get(); // 判断为空的话,创建连接并绑定到当前线程 if(connection == null) { - synchronized(obj) { - if((connection = tl.get()) == null) { - connection = createConnection(); - tl.set(connection); - } - } + connection = createConnection(); + tl.set(connection); } return connection; }