Mar 2, 2022 Replies: 9 This is a wrapper for HikariCP which is a database connection pool manager (https://github.com/brettwooldridge/HikariCP) From the github page; Fast, simple, reliable. HikariCP is a "zero-overhead" production ready JDBC connection pool. At roughly 130Kb, the library is very light. A user called "mindful" had previously wrapped this library but he hasnt been on the forum since March 2021 - see here - and his wrapper was for an older version. A while back I wrote a semi-functional wrapper for HikariCP 5.x for some testing I was doing so I thought I should mention it here. DOWNLOAD LINK; https://ope.nz/public/HikariCP_5.01.zip Library code; https://github.com/ope-nz/HikariCP To create a connection pool (in this case is for SQLite) B4X: Copy Dim url As String = $"jdbc:sqlite:${File.DirApp}\test.db"$ 'Initialize(String JdbcUrl, String user, String password, String ConnectionTestQuery) cp.Initialize(url,Null,Null,Null) To use the connection pool (eg in a handler class); B4X: Copy 'Handler class Sub Class_Globals Dim DB As SQL End Sub Public Sub Initialize Dim DB As SQL DB = Main.cp.GetConnection 'Use DB as per normal SQL connection ' Close the connecton to return to the pool, otherwise another connection will created until this one is deemed idle DB.Close End Sub You can adjust some settings directly via the library eg B4X: Copy cp.MaximumPoolSize = 100 cp.MaxLifetime = 1000 cp.MinimumIdle = 1000 Log(cp.MaximumPoolSize) Log(cp.MaxLifetime) Log(cp.MinimumIdle) To get stats use these methods below. Note that calling these methods before requesting a connection results in a null exception so the library will return -1 to avoid any errors. B4X: Copy Log(cp.ActiveConnections) Log(cp.IdleConnections) Log(cp.ThreadsAwaitingConnection) Log(cp.TotalConnections) Note: There are many config options and I have only implemented the ones I needed. If there is enough interest I can implement more or you can simply use JavaObject to change the config as per mindfuls post. Config documentation; https://github.com/brettwooldridge/HikariCP#gear-configuration-knobs-baby If you wish to create a read only connection to a SQLite database you need to initialize this way. The connection is faster as a result. B4X: Copy Dim url As String = $"jdbc:sqlite:${File.DirApp}\db.sqlite?open_mode=1"$ cp.Initialize(url,Null,Null,Null) Log(cp.IsInitialised) cp.MaximumPoolSize = 50 cp.MinimumIdle = 10 cp.ReadOnly = True cp.AutoCommit = False Last edited: Mar 21, 2022 Click to expand...
This is a wrapper for HikariCP which is a database connection pool manager (https://github.com/brettwooldridge/HikariCP) From the github page; Fast, simple, reliable. HikariCP is a "zero-overhead" production ready JDBC connection pool. At roughly 130Kb, the library is very light. A user called "mindful" had previously wrapped this library but he hasnt been on the forum since March 2021 - see here - and his wrapper was for an older version. A while back I wrote a semi-functional wrapper for HikariCP 5.x for some testing I was doing so I thought I should mention it here. DOWNLOAD LINK; https://ope.nz/public/HikariCP_5.01.zip Library code; https://github.com/ope-nz/HikariCP To create a connection pool (in this case is for SQLite) B4X: Copy Dim url As String = $"jdbc:sqlite:${File.DirApp}\test.db"$ 'Initialize(String JdbcUrl, String user, String password, String ConnectionTestQuery) cp.Initialize(url,Null,Null,Null) To use the connection pool (eg in a handler class); B4X: Copy 'Handler class Sub Class_Globals Dim DB As SQL End Sub Public Sub Initialize Dim DB As SQL DB = Main.cp.GetConnection 'Use DB as per normal SQL connection ' Close the connecton to return to the pool, otherwise another connection will created until this one is deemed idle DB.Close End Sub You can adjust some settings directly via the library eg B4X: Copy cp.MaximumPoolSize = 100 cp.MaxLifetime = 1000 cp.MinimumIdle = 1000 Log(cp.MaximumPoolSize) Log(cp.MaxLifetime) Log(cp.MinimumIdle) To get stats use these methods below. Note that calling these methods before requesting a connection results in a null exception so the library will return -1 to avoid any errors. B4X: Copy Log(cp.ActiveConnections) Log(cp.IdleConnections) Log(cp.ThreadsAwaitingConnection) Log(cp.TotalConnections) Note: There are many config options and I have only implemented the ones I needed. If there is enough interest I can implement more or you can simply use JavaObject to change the config as per mindfuls post. Config documentation; https://github.com/brettwooldridge/HikariCP#gear-configuration-knobs-baby If you wish to create a read only connection to a SQLite database you need to initialize this way. The connection is faster as a result. B4X: Copy Dim url As String = $"jdbc:sqlite:${File.DirApp}\db.sqlite?open_mode=1"$ cp.Initialize(url,Null,Null,Null) Log(cp.IsInitialised) cp.MaximumPoolSize = 50 cp.MinimumIdle = 10 cp.ReadOnly = True cp.AutoCommit = False
alwaysbusy Expert Licensed User Longtime User Mar 2, 2022 #2 @tchart I have been using Mindfuls library with HikariCP 5.x for quite some time now using Code: Copy #AdditionalJar: HikariCP-5.0.0.jar #AdditionalJar: slf4j-api-1.7.32 #AdditionalJar: slf4j-simple-1.7.32.jar Any advantages your library has over Mindfuls? Alwaysbusy
@tchart I have been using Mindfuls library with HikariCP 5.x for quite some time now using Code: Copy #AdditionalJar: HikariCP-5.0.0.jar #AdditionalJar: slf4j-api-1.7.32 #AdditionalJar: slf4j-simple-1.7.32.jar Any advantages your library has over Mindfuls? Alwaysbusy
tchart Well-Known Member Licensed User Longtime User Mar 2, 2022 #3 alwaysbusy said: Any advantages your library has over Mindfuls? Click to expand... Not really. they are functionally the same, in fact I used his library code to begin with. Ive just started adding getters/setters for the config to avoid using RunMethod. Mindful did not specify DependsOn in the library so you can use whatever version of HikariCP you want but you do need to then specify the jars via AdditionalJar as youve shown. Also his post if from 2018 so I so anyone stumbling on it may not realise there are newer versions of the library available - or the fact that you can use newer versions of HikariCP with it (if you know how).
alwaysbusy said: Any advantages your library has over Mindfuls? Click to expand... Not really. they are functionally the same, in fact I used his library code to begin with. Ive just started adding getters/setters for the config to avoid using RunMethod. Mindful did not specify DependsOn in the library so you can use whatever version of HikariCP you want but you do need to then specify the jars via AdditionalJar as youve shown. Also his post if from 2018 so I so anyone stumbling on it may not realise there are newer versions of the library available - or the fact that you can use newer versions of HikariCP with it (if you know how).
incendio Well-Known Member Licensed User Longtime User Mar 3, 2022 #4 Compare to JRDC2 with one is better for performance and easy to maintain ?
tchart Well-Known Member Licensed User Longtime User Mar 3, 2022 #5 incendio said: Compare to JRDC2 with one is better for performance and easy to maintain ? Click to expand... They are for different purposes. JRDC2 provides a REST interface for access your database. A database pool connection manager is about managing multiple database connections within an application.
incendio said: Compare to JRDC2 with one is better for performance and easy to maintain ? Click to expand... They are for different purposes. JRDC2 provides a REST interface for access your database. A database pool connection manager is about managing multiple database connections within an application.
Erel B4X founder Staff member Licensed User Longtime User Mar 6, 2022 #6 The correct comparison is jRDC2 with the default connection pool (c3p0) vs jRDC2 with Hikari.
EnriqueGonzalez Expert Licensed User Longtime User Mar 11, 2022 #7 alwaysbusy said: @tchart I have been using Mindfuls library with HikariCP 5.x for quite some time now using Click to expand... I tried the same approach as you a month ago but there was a bug that after a couple of days (it could range between 2 days or a week) hickari loses reference to the created connections stalling the app. I know it was the version because when I reverted back to V4 it didn't happen at all. I will try @tchart library and see if the bug is no longer there
alwaysbusy said: @tchart I have been using Mindfuls library with HikariCP 5.x for quite some time now using Click to expand... I tried the same approach as you a month ago but there was a bug that after a couple of days (it could range between 2 days or a week) hickari loses reference to the created connections stalling the app. I know it was the version because when I reverted back to V4 it didn't happen at all. I will try @tchart library and see if the bug is no longer there
alwaysbusy Expert Licensed User Longtime User Mar 11, 2022 #8 EnriqueGonzalez said: I tried the same approach as you a month ago but there was a bug that after a couple of days (it could range between 2 days or a week) hickari loses reference to the created connections stalling the app. I know it was the version because when I reverted back to V4 it didn't happen at all. I will try @tchart library and see if the bug is no longer there Click to expand... That is very interesting to know as of late I also got this problem with 5.x. Could you post me the exact version of V4 you are using that doesn't have this problem? Thanks!
EnriqueGonzalez said: I tried the same approach as you a month ago but there was a bug that after a couple of days (it could range between 2 days or a week) hickari loses reference to the created connections stalling the app. I know it was the version because when I reverted back to V4 it didn't happen at all. I will try @tchart library and see if the bug is no longer there Click to expand... That is very interesting to know as of late I also got this problem with 5.x. Could you post me the exact version of V4 you are using that doesn't have this problem? Thanks!
EnriqueGonzalez Expert Licensed User Longtime User Mar 11, 2022 #9 alwaysbusy said: Could you post me the exact version of V4 Click to expand... right it is: HikariCP-4.0.3.jar
alwaysbusy said: Could you post me the exact version of V4 Click to expand... right it is: HikariCP-4.0.3.jar
P prajinpraveen Active Member Licensed User Longtime User Mar 19, 2022 #10 Good Day, any ways to check active connections(getActiveConnections) count like we do with c3p0 thanks Last edited: Mar 19, 2022
Good Day, any ways to check active connections(getActiveConnections) count like we do with c3p0 thanks