Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent failure on Hikari Pool initialization if database connection fails

Tags:

scala

hikaricp

I have a project which uses Hikari Connection Pool. I create connection pool for all the databases one by one as new HikariDataSource(someConfig)

This works fine when all the databases are available. But if any of the database is offline the Play project gives the below error:

[RuntimeException: java.lang.ExceptionInInitializerError]

I do not want the application to crash if just a few of the databases are offline.

How can I avoid this error from crashing the application?

Note: I am using HikariCP package on its own in another subproject. I am not using play-hikari plugin.

like image 255
Priya R Avatar asked Jan 01 '26 03:01

Priya R


1 Answers

set hikaricp property initializationFailFast=false. its description from hikaricp site:

This property controls whether the pool will "fail fast" if the pool cannot be seeded with initial connections successfully. If you want your application to start even when the database is down/unavailable, set this property to false. Default: true

like image 106
Nitin Avatar answered Jan 04 '26 11:01

Nitin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!