Re: MYSQL 8.0.18 xdev, total connections are keeps increasing
Hello Filipe Silva,
Thanks for your reply.
Appreciate your help.
To give more details,
Here is the approach:
-------------------
Created a singleton class for DBConnection
In the DAO get the DB Session and query the data
Close the DB Session in the finally making sure that the session is closed.
Problem: As stated in the original thread, number of connections are getting increased as the usage increases. Our understanding is that,as we are closing the session, MYSQL automatically closes the respective connections.
Please correct me where am I going wrong here?
Here is the pseudo code:
----------------------
DBConnection.java - Singleton class
class DBConnection {
ClientFactory cf = new ClientFactory();
Client client = cf.getClient ("url", "{\"pooling\":{\"enabled\":true, \"maxSize\":15, \"queueTimeout\":0, \"maxIdleTime\": 0} }");
private DBConnection ()...
public static DBConnection getRepoInstance() {
if(repoInstance == null) {
LOGGER.info("Creating new instance");
repoInstance=new DBConnection();
}
return repoInstance;
}
public getDBSession() {
synchronized (....) {
Session dbSession = client.getSession();
}
return dbSession;
}
public void closeDBSession( Session session) {
synchronized (....) {
session.close();
}
} // End of closeDBSession
} // End of Class
// Pseudo code for calling the above methods from DAO layer
class Consumer {
public UserDetails getConsumerDetails( String userID) {
// Create object of DBSession
Session dbSession = DBConnection.getRepoInstance().getDBSession();
try {
dbSession.getSchema("COnsumerDetails");
... .... // DB Queries
}
finally { // Close the session
DBConnection.getRepoInstance().closeSession(dbSession);
}
}
}
Subject
Written By
Posted
Re: MYSQL 8.0.18 xdev, total connections are keeps increasing
October 13, 2021 10:19AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.