09052029:对这个资产展示使用线程池的方法去做,第五次优化代码
parent
230606de1d
commit
6c2130678c
|
@ -178,9 +178,12 @@ public class DataValueServiceImpl extends ServiceImpl<DataValueMapper, DataValue
|
||||||
|
|
||||||
private int getTotalRecords(MysqlPool mysqlPool, String tableName) throws SQLException {
|
private int getTotalRecords(MysqlPool mysqlPool, String tableName) throws SQLException {
|
||||||
try (Connection conn = mysqlPool.getConn();
|
try (Connection conn = mysqlPool.getConn();
|
||||||
Statement statement = conn.createStatement();
|
Statement statement = conn != null ? conn.createStatement() : null;
|
||||||
ResultSet resultSet = statement.executeQuery("SELECT COUNT(*) FROM " + tableName)) {
|
ResultSet resultSet = statement != null ? statement.executeQuery("SELECT COUNT(*) FROM " + tableName) : null) {
|
||||||
if (resultSet.next()) {
|
if (conn == null) {
|
||||||
|
throw new SQLException("Failed to get database connection");
|
||||||
|
}
|
||||||
|
if (resultSet != null && resultSet.next()) {
|
||||||
return resultSet.getInt(1);
|
return resultSet.getInt(1);
|
||||||
} else {
|
} else {
|
||||||
throw new SQLException("Failed to get total record count");
|
throw new SQLException("Failed to get total record count");
|
||||||
|
@ -192,8 +195,11 @@ public class DataValueServiceImpl extends ServiceImpl<DataValueMapper, DataValue
|
||||||
List<DataValue> batchResults = new ArrayList<>();
|
List<DataValue> batchResults = new ArrayList<>();
|
||||||
String query = "SELECT * FROM " + tableName + " LIMIT ? OFFSET ?";
|
String query = "SELECT * FROM " + tableName + " LIMIT ? OFFSET ?";
|
||||||
|
|
||||||
try (Connection conn = mysqlPool.getConn();
|
try (Connection conn = mysqlPool.getConn()) {
|
||||||
PreparedStatement preparedStatement = conn.prepareStatement(query)) {
|
if (conn == null) {
|
||||||
|
throw new SQLException("Failed to get database connection");
|
||||||
|
}
|
||||||
|
try (PreparedStatement preparedStatement = conn.prepareStatement(query)) {
|
||||||
preparedStatement.setInt(1, BATCH_SIZE);
|
preparedStatement.setInt(1, BATCH_SIZE);
|
||||||
preparedStatement.setInt(2, offset);
|
preparedStatement.setInt(2, offset);
|
||||||
|
|
||||||
|
@ -222,6 +228,7 @@ public class DataValueServiceImpl extends ServiceImpl<DataValueMapper, DataValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue