Good day,
Goal: Log a transaction in a database (mysql) using the Mysql JDBC jar load balanced (multi thread).
I've looked through the blogs & forums as I can't really believe that I'm the first person encountering this problem, though I'm not finding anything related.
I've successfully established a connection to Mysql and queried the server inside a TM participant, though I'm coming across an interesting issue:
- If each participant creates it's own instance of a connection to Mysql, the Mysql will be semi flooded with connection opening and closing
- If I centralize the Mysql implementation to a single class and make it a Singleton, then everyone might across the system (single JVM) will thus wait in a serial queue (assuming my understanding that a Singleton applies to a JVM)
- If I create a thread pool (say 10) and then return a reference to that thread using my Singleton class and then reserve that thread specifically for the calling class, then other classes might end up waiting for a thread if I run out of threads. Assuming I implement it correctly, calling classes might need some form of logic to wait for a connection thread. This solution might be in danger if threads are not released appropriately. The best reference I could come up with is:
http://dev.mysql.com/tech-resources/articles/connection_pooling_with_connectorj.html
Note: This is done using jPOS and not JPosEE.
Does anyone have a suggestion on how this should be done in jPOS?
Pieter