I've been reading dozens of topics here with no real enlightment: I'm running a standalone java app, on a Synology NAS with Java 8. I also installed MariaDB on the same NAS. So everything is local.
I am able to setup a datasource and get a connection, but I would like to be able to access it in any instance of any of my classes / threads for connection pooling. Everything seem to show that I would need JNDI. But I don't have a J2EE container and this seems overkill for my need. Idem for developping my own implementation of JNDI.
I've seen replies to similar questions where people suggest C3PO. But this is just another datasource implementation. I don't think it solves the standalone app issue with no way to access datasource from anywhere in the code :
How to retrieve DB connection using DataSource without JNDI?
Is there another way to share a datasource across java threads ?
- Can I pass the Datasource instance as a parameter to each thread, so they can get a connection when they need ?
- Should I assign a given connection to each thread - also passed as a parameter ? and in this case, never really close it properly ?
- Or should I really install something like tomcat, jboss, jetty ? are they equivalent ? Is there a super light J2EE container that could provide JNDI ?
Thanks
Vincent