last day (14 days later) » 

1:02 PM
0
A: HikariCP without Framework

NikemYour error messages says, that your Database has too many connections currently opened. So first thing you can consult your DB documentation and increase connections limit. Or talk to you DB admin, if you have one. The probable reason is that you create new datasource for every new instance of a...

 
No DB admin, its just me...making connection pool smaller did not solve the problem. I guess maybe its the way i create the pool itself?Any suggestions on that side?
 
Seems to be Ok to me... Have you tried to increase connection limit in your DB
 
As M. Deinum comment says the problem of too many connections comes because i create many instances of HikariDataSource which in every creation, 10 connections are added.
I updated a link to a stackoverflow question that does that, maintain one instance of DataSource...though according to an accepted answer a Double-checked locking problem might occur which i still don't know how to solve...could you?
 
@YunusEinsteinium I have updated my answer. I believe I now understand the real root cause of your troubles :)
 
instead of initializing it in a constructor i use static block, so you mean the class will have no constructor?... and a quick question...is the method you suggesting thread safe?
 
1:02 PM
Yes, static block initialisation is always thread safe. And your DBManager will still have default empty constructor.
 
This code DBManager.hikariDS = new HikariDataSource(hikariConfig) has error say cannot assign a value to final variable hikariDS
 
then remove final. It is not really needed.
Or, change this line to
hikariDS = new HikariDataSource(hikariConfig);
Then it compiles with final keyword as well
 
1:51 PM
Does it work? Or can I help you somehow?
 
2:03 PM
So far, its working fine...i hope no thread-safety problems will occur when i start using threads
Thank you for helping, this problem has really been bugging me for days
 
Not a problem. Hikari datasource is thread-safe as is static initialisation. So there shouldn't be any problems.
Care to upvote/accept my answer? :)
Thank you :)
 

last day (14 days later) »