diff --git a/dbsyncer-biz/pom.xml b/dbsyncer-biz/pom.xml
index 44a2e1412a77243a67d4637b4eb2537c32080038..a569a282db492fa4738cac351396ce25a38a0efe 100644
--- a/dbsyncer-biz/pom.xml
+++ b/dbsyncer-biz/pom.xml
@@ -5,7 +5,7 @@
dbsyncer
org.ghi
- 1.2.6_1012
+ 1.2.7
4.0.0
dbsyncer-biz
diff --git a/dbsyncer-cache/pom.xml b/dbsyncer-cache/pom.xml
index 893520d9ac48a8930ad296bed7687183761fefbe..73fbb270ac8cfb0343085b3eeeae4c46d8ca7f8a 100644
--- a/dbsyncer-cache/pom.xml
+++ b/dbsyncer-cache/pom.xml
@@ -4,7 +4,7 @@
dbsyncer
org.ghi
- 1.2.6_1012
+ 1.2.7
4.0.0
dbsyncer-cache
diff --git a/dbsyncer-cluster/pom.xml b/dbsyncer-cluster/pom.xml
index c4ac9db9ff970a7ce6b7fb7b728c4ef174dd69f8..ee4d930f4ce285fccb80cb2f89dfb8fbc85ab10d 100644
--- a/dbsyncer-cluster/pom.xml
+++ b/dbsyncer-cluster/pom.xml
@@ -5,7 +5,7 @@
dbsyncer
org.ghi
- 1.2.6_1012
+ 1.2.7
4.0.0
dbsyncer-cluster
diff --git a/dbsyncer-common/pom.xml b/dbsyncer-common/pom.xml
index 9f98c6fa8e1173b7cadcd2d4518815931d4072b5..ab0490d880efa4c883b9cd3ea6e00f1e77c21443 100644
--- a/dbsyncer-common/pom.xml
+++ b/dbsyncer-common/pom.xml
@@ -5,7 +5,7 @@
dbsyncer
org.ghi
- 1.2.6_1012
+ 1.2.7
4.0.0
dbsyncer-common
diff --git a/dbsyncer-connector/pom.xml b/dbsyncer-connector/pom.xml
index c600ebd35562ddab3995e8b40e29336541b14f47..28a57cb7636aeec2d696f806ae19ee33279e0df9 100644
--- a/dbsyncer-connector/pom.xml
+++ b/dbsyncer-connector/pom.xml
@@ -5,7 +5,7 @@
dbsyncer
org.ghi
- 1.2.6_1012
+ 1.2.7
4.0.0
dbsyncer-connector
diff --git a/dbsyncer-connector/src/main/java/org/dbsyncer/connector/database/DatabaseConnectorMapper.java b/dbsyncer-connector/src/main/java/org/dbsyncer/connector/database/DatabaseConnectorMapper.java
index 22e09cf783191b3ce5517a0c0bfb66b908b8f7fb..a15c1a45fa8a18c89df9497241cbe9352b47e533 100644
--- a/dbsyncer-connector/src/main/java/org/dbsyncer/connector/database/DatabaseConnectorMapper.java
+++ b/dbsyncer-connector/src/main/java/org/dbsyncer/connector/database/DatabaseConnectorMapper.java
@@ -5,7 +5,6 @@ import org.dbsyncer.connector.ConnectorException;
import org.dbsyncer.connector.config.DatabaseConfig;
import org.dbsyncer.connector.database.ds.SimpleConnection;
import org.dbsyncer.connector.database.ds.SimpleDataSource;
-import org.dbsyncer.connector.util.DatabaseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.EmptyResultDataAccessException;
@@ -33,7 +32,7 @@ public class DatabaseConnectorMapper implements ConnectorMapper pool = new LinkedBlockingQueue<>(300);
- private long lifeTime = 60 * 1000;
+ /**
+ * 有效期(毫秒),默认60s
+ */
+ private final long KEEP_ALIVE = 60000;
+ /**
+ * 有效检测时间(秒),默认10s
+ */
+ private final int VALID_TIMEOUT_SECONDS = 10;
private String driverClassName;
private String url;
private String username;
@@ -30,21 +39,19 @@ public class SimpleDataSource implements DataSource, AutoCloseable {
@Override
public Connection getConnection() throws SQLException {
- SimpleConnection poll = null;
- int i = 3;
- do {
- if (pool.isEmpty()) {
- pool.offer(createConnection());
- }
- poll = pool.poll();
- if (null != poll) {
- break;
- }
- i--;
- } while (i > 1);
-
+ SimpleConnection poll = pool.poll();
if (null == poll) {
- poll = createConnection();
+ return createConnection();
+ }
+
+ // 连接无效
+ if (!poll.isValid(VALID_TIMEOUT_SECONDS)) {
+ return createConnection();
+ }
+
+ // 连接过期
+ if (isExpired(poll)) {
+ return createConnection();
}
return poll;
}
@@ -91,26 +98,41 @@ public class SimpleDataSource implements DataSource, AutoCloseable {
@Override
public void close() {
- pool.forEach(c -> c.closeQuietly());
+ pool.forEach(c -> c.close());
}
- private SimpleConnection createConnection() throws SQLException {
- return new SimpleConnection(this, DatabaseUtil.getConnection(driverClassName, url, username, password));
- }
+ public void close(Connection connection) {
+ if (connection != null && connection instanceof SimpleConnection) {
+ SimpleConnection simpleConnection = (SimpleConnection) connection;
+ // 连接过期
+ if (isExpired(simpleConnection)) {
+ simpleConnection.close();
+ return;
+ }
- public String getDriverClassName() {
- return driverClassName;
+ // 回收连接
+ pool.offer(simpleConnection);
+ }
}
- public BlockingQueue getPool() {
- return pool;
+ /**
+ * 连接是否过期
+ *
+ * @param connection
+ * @return
+ */
+ private boolean isExpired(SimpleConnection connection) {
+ return connection.getActiveTime() + KEEP_ALIVE < Instant.now().toEpochMilli();
}
- public long getLifeTime() {
- return lifeTime;
+ /**
+ * 创建新连接
+ *
+ * @return
+ * @throws SQLException
+ */
+ private SimpleConnection createConnection() throws SQLException {
+ return new SimpleConnection(DatabaseUtil.getConnection(driverClassName, url, username, password), StringUtil.equals(driverClassName, "oracle.jdbc.OracleDriver"));
}
- public void setLifeTime(long lifeTime) {
- this.lifeTime = lifeTime;
- }
}
\ No newline at end of file
diff --git a/dbsyncer-listener/pom.xml b/dbsyncer-listener/pom.xml
index 9e1dce2b123227eea95f4b0cfd77d0a7a7753091..4ba80f8d276ef96e92f692ff91ae7e360d47739f 100644
--- a/dbsyncer-listener/pom.xml
+++ b/dbsyncer-listener/pom.xml
@@ -5,7 +5,7 @@
dbsyncer
org.ghi
- 1.2.6_1012
+ 1.2.7
4.0.0
dbsyncer-listener
diff --git a/dbsyncer-manager/pom.xml b/dbsyncer-manager/pom.xml
index 34126bdd60637de10a1fd9f347d4cc540c4655b0..43b9d6062057204e8247cc7428827d72d934d25c 100644
--- a/dbsyncer-manager/pom.xml
+++ b/dbsyncer-manager/pom.xml
@@ -5,7 +5,7 @@
dbsyncer
org.ghi
- 1.2.6_1012
+ 1.2.7
4.0.0
dbsyncer-manager
diff --git a/dbsyncer-monitor/pom.xml b/dbsyncer-monitor/pom.xml
index 86fe179dc7d9a77ad83ce336682c7cc4c386cc0f..52a62b61d64d5c4f3124ea101566d44925a017b1 100644
--- a/dbsyncer-monitor/pom.xml
+++ b/dbsyncer-monitor/pom.xml
@@ -5,7 +5,7 @@
dbsyncer
org.ghi
- 1.2.6_1012
+ 1.2.7
4.0.0
dbsyncer-monitor
diff --git a/dbsyncer-parser/pom.xml b/dbsyncer-parser/pom.xml
index e55cad9c49b7a3816acf1a2da0cf38bb3d792635..27de9bef29b3fe37c1f41c4e0e5bbf3ad0f0c549 100644
--- a/dbsyncer-parser/pom.xml
+++ b/dbsyncer-parser/pom.xml
@@ -5,7 +5,7 @@
dbsyncer
org.ghi
- 1.2.6_1012
+ 1.2.7
4.0.0
dbsyncer-parser
diff --git a/dbsyncer-plugin/pom.xml b/dbsyncer-plugin/pom.xml
index 9b3c73ffa49c9de456c4362f67c7a51f733c5723..ab43dc467442a2d3878bdc6733fb2df1ea04a888 100644
--- a/dbsyncer-plugin/pom.xml
+++ b/dbsyncer-plugin/pom.xml
@@ -5,7 +5,7 @@
dbsyncer
org.ghi
- 1.2.6_1012
+ 1.2.7
4.0.0
dbsyncer-plugin
diff --git a/dbsyncer-storage/pom.xml b/dbsyncer-storage/pom.xml
index f1ad47f43dbcf9dae3a8b17296940e81a4d8b927..490637ed26782473d87dc856c9fbb3cb0317d153 100644
--- a/dbsyncer-storage/pom.xml
+++ b/dbsyncer-storage/pom.xml
@@ -5,7 +5,7 @@
dbsyncer
org.ghi
- 1.2.6_1012
+ 1.2.7
4.0.0
dbsyncer-storage
diff --git a/dbsyncer-web/pom.xml b/dbsyncer-web/pom.xml
index 849a775496d06f313f435736210562ef4f1abc33..abf96882736f73282eaff6a5a06d9b9dc1db6490 100644
--- a/dbsyncer-web/pom.xml
+++ b/dbsyncer-web/pom.xml
@@ -5,7 +5,7 @@
dbsyncer
org.ghi
- 1.2.6_1012
+ 1.2.7
4.0.0
dbsyncer-web
diff --git a/pom.xml b/pom.xml
index 6bc284f1e4588880252f548ca4be15d8db04b5e6..5faf49bc77e7be9579e4c2fd8e71cf18b3910146 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
org.ghi
dbsyncer
- 1.2.6_1012
+ 1.2.7
pom
dbsyncer
https://gitee.com/ghi/dbsyncer
diff --git a/version.cmd b/version.cmd
index f489d12089c6a2f7cf3c193c5821b077ed7518dc..7abd903f2992e1b7644c8a5f795955fa936a08ab 100644
--- a/version.cmd
+++ b/version.cmd
@@ -1,7 +1,7 @@
@echo off
set CURRENT_DATE=%date:~5,2%%date:~8,2%
-set VERSION=1.2.6_%CURRENT_DATE%
+set VERSION=1.2.7_%CURRENT_DATE%
set /p APP_VERSION=Please enter a new version number(%VERSION%): || set APP_VERSION=%VERSION%
echo %APP_VERSION%