升级:1、增加界面夜间模式

2、qtask 功能交互升级
     3、mysql连接管理增加心跳保活
     4、其他修改
This commit is contained in:
2024-03-31 00:34:26 +08:00
parent 8cc55c2c4b
commit 4dcebf32de
37 changed files with 1136 additions and 301 deletions

View File

@@ -28,7 +28,7 @@ public class DbExecutors {
MetaService metaService = MetaKit.getMetaService(fBean.getName(), fBean.getPlatToken());
MetaTable mainTable = MetaKit.getMetaTableByAlias(metaService.getTable());
DbKit dbKit = MetaKit.getDbKit(mainTable.getDbPlatId(), mainTable.getCatalog());
//System.out.printf("----------------%n countSql:%s%n findSql:%s%n----------------%n", sqls[0], sqls[1]);
System.out.printf("----------------%n countSql:%s%n findSql:%s%n----------------%n", sqls[0], sqls[1]);
CompletableFuture<Integer> countFuture = CompletableFuture.supplyAsync(() -> dbKit.findColumn(sqls[0], int.class));
CompletableFuture<List<Map>> listFuture = CompletableFuture.supplyAsync(() -> dbKit.queryList(sqls[1], Map.class));

View File

@@ -24,6 +24,49 @@ public class DbSourceMysql implements DbSource {
private DbAccount dbAccount;
private String catalog;
private static boolean ping;
static {
// MYSQL PING
synchronized (DbSourceMysql.class) {
if (!ping) {
new Thread(() -> {
while (true) {
conns.forEach((k, vs) -> {
if (vs.isEmpty()) {
return;
}
try {
for (int i = 0; i < counter.get(k).get(); i++) {
Connection conn = vs.poll();
if (conn == null) {
return;
}
try {
conn.prepareStatement("SELECT 1").executeQuery();
vs.put(conn);
} catch (SQLException e) {
counter.get(k).decrementAndGet(); // 连接总数减去1
e.printStackTrace();
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
});
try {
Thread.sleep(1000 * 60);
} catch (InterruptedException ignored) {
}
}
}).start();
ping = true;
}
}
}
public DbSourceMysql() {
}
@@ -179,21 +222,34 @@ public class DbSourceMysql implements DbSource {
}
private synchronized Connection connection(int n) throws InterruptedException, SQLException {
LinkedBlockingQueue<Connection> queue = conns.getOrDefault(accountKey, new LinkedBlockingQueue<>(15));
LinkedBlockingQueue<Connection> queue = conns.get(accountKey);
if (queue == null) {
queue = new LinkedBlockingQueue<>(15);
conns.put(accountKey, queue);
}
AtomicInteger num = counter.get(accountKey);
if (num == null) {
num = new AtomicInteger(0);
}
Connection conn = null;
AtomicInteger num = counter.getOrDefault(accountKey, new AtomicInteger(0));
if (queue.size() == 0 && num.get() < 15) { // 创建总连接数小于15且暂无可用连接
conn = DriverManager.getConnection(dbAccount.getUrl(), dbAccount.getUser(), dbAccount.getPwd());
if (queue.isEmpty() && num.get() < 15) { // 创建总连接数小于15且暂无可用连接
String url = dbAccount.getUrl();
String user = dbAccount.getUser();
String pwd = dbAccount.getPwd();
conn = DriverManager.getConnection(url, user, pwd);
int x = num.incrementAndGet();
counter.put(accountKey, num);
System.out.println("创建新的连接:" + x);
System.out.printf("创建新的连接[%s]:%s\n", x, url + "@" + user);
} else {
conn = queue.take();
if (!conn.isValid(5)) {
conn = connection(++n);
}
}
conns.put(accountKey, queue);
//conns.put(accountKey, queue);
return conn;
}