دنبال کننده ها

۱۳۹۶ دی ۱۰, یکشنبه

spring - Throwing exception in MultiTenantConnectionProvider, exhausts the connections in Connection Pool

[ad_1]



I am using multi tenancy by schema in MySQL as,



class SchemaPerTenantConnectionProvider : MultiTenantConnectionProvider 

@Autowired
private lateinit var dataSource: DataSource

@Throws(SQLException::class)
override fun getAnyConnection() = this.dataSource.connection

@Throws(SQLException::class)
override fun releaseAnyConnection(connection: Connection)
connection.close()


@Throws(SQLException::class)
override fun getConnection(tenantIdentifier: String): Connection
val connection = this.anyConnection
try
connection.createStatement().execute("USE $tenantIdentifier ")
catch (e: SQLException)
throw SQLException("Could not alter JDBC connection to schema [$tenantIdentifier]")


return connection

...



My connection pool size is 10, now if any invalid tenantIdentifier is passed 10 times, 10 connections are exhausted, after that application is unable to acquire any connection.



Tried throwing Exception, HibernateException and it didn't help. Using connection with default schema will fetch wrong results. Is there a way to handle this scenario in getConnection(), to not to exhaust connection limits?




[ad_2]

لینک منبع