0

I am getting below exception in my code:

Caused by: java.sql.SQLTransientConnectionException: HikariPool-2 - Connection is not available, request timed out after 30006ms.
    at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:695)
    at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:197)
 
Caused by: java.sql.SQLNonTransientConnectionException: Too many connections
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:832)
    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)

and below is the sample code where I am getting this exception when I try to run this code with x number of concurrent users

@Transactional     
public List<Object> a() {      
    return b();     
}     

@Transactional     
public List<Object> b() {       
    List<Object> listToReturn = new ArrayList<>();      
    listToReturn .add(create());     
    return listToReturn;     
}      

public create() {          
      Object object= Repository.save(object); //Saves in jpa repository       
}   

can anyone help me what is the reason ?

Mohsin
  • 1
  • 1
  • Your pool is creating more connections than your MySQL server installation allows. Change your connection pool to create a smaller number of connections (200 sounds way too much, correctly programmed, you'd be surprised how few connections you need to serve a lot of requests), or increase the maximum number of connections allowed in your MySQL configuration. – Mark Rotteveel Feb 19 '21 at 12:04
  • @MarkRotteveel Dont you think there is some issue in code that is using so many connections ?are the connections remaining open ? what is the behavior of function with transactional with transactional ? – Mohsin Feb 22 '21 at 04:50
  • That entirely depends on your configuration, and the calling code. Given you don't provide a [mre] nor include your data source config, we can't answer that beyond pointing you to a canonical answer for your error. – Mark Rotteveel Feb 22 '21 at 07:12

0 Answers0