Wie begrenzte ich Verbindungen von Tomcat mit Hikari CP?

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Wie begrenzte ich Verbindungen von Tomcat mit Hikari CP?

by Anonymous » 05 Mar 2025, 11:31

Ich habe eine Android -App, die den Tomcat -Server verwendet, um eine Verbindung zu einer Firebird -Datenbank herzustellen. Unabhängig von der Anzahl der setMaximumpoolsize , Tomcat erstellt eine Reihe von Verbindungen, die um ein Vielfaches höher als dieser Wert sind. class = "Lang-Java PrettyPrint-Override">

Code: Select all

public class DBConnection {
private static final int READ_ONLY = 0;
private static final int READ_WRITE = 1;
private static HikariDataSource datasource;

public static HikariDataSource getDataSource(String dbIP, String dbName,
String dbUsername, String dbPassword, int conType) {
HikariConfig config = new HikariConfig();

config.setDriverClassName(Constants.DB_DRIVER);
config.setJdbcUrl(Constants.DB_URL + Constants.DB_IP + "/"
+ Constants.DB_NAME + "?dialect=3&lc_ctype=UNICODE_FSS");
config.setUsername(Constants.DB_USER);
config.setPassword(Utility.dbDecrypt(Constants.DB_PWD));

config.setMaximumPoolSize(8);

datasource = new HikariDataSource(config);
return datasource;
}

@SuppressWarnings("finally")
public static Connection createConnection(String dbIP, String dbName,
String dbUsername, String dbPassword, int conType) {
Connection con = null;

System.setProperty("org.firebirdsql.jdbc.processName", "Tomcat");

if (datasource == null) {

// Create new datasource
datasource = (HikariDataSource) getDataSource(dbIP, dbName,
dbUsername, dbPassword, conType);
}

try {
con = datasource.getConnection();

if (conType == READ_ONLY) {
con.setReadOnly(true);
} else {
con.setReadOnly(false);
}
} finally {
return con;
}
}
}
< /code>
Und hier ist, wie ich die Verbindung verwende: < /p>
public static boolean checkLogin(String username, String pwd, String dbIP,
String dbName, String dbUsername, String dbPassword)
throws Exception {
boolean isUserAvailable = false;
Connection dbConn = null;

try {
try {
dbConn = DBConnection.createConnection(dbIP, dbName,
dbUsername, dbPassword, READ_ONLY);
} catch (Exception e) {
if (dbConn != null) {
dbConn.close();
}
e.printStackTrace();
}
Statement stmt = dbConn.createStatement();
String query = "SELECT NAME_USL, FULL_NAME_USL, PASSWORD_USL "
+ "FROM USER_LIST " + "WHERE NAME_USL = '" + username
+ "' AND PASSWORD_USL = '" + pwd + "'";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
isUserAvailable = true;
}
} catch (SQLException sqle) {
sqle.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (dbConn != null) {
dbConn.close();
}
}
return isUserAvailable;
}

Top