This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi ALL I am a bit confused about EJBs opening connections to DB. I have 3 EJBs getting Connections from DataSource. EJB A gets a connection from Datasource, performs some DB operation and calls EJB B, EJB B does the same as EJB A and calls EJB C. When EJB C also accesses the DataSource to open connection, How many physical connections are opened to the DB or in otherwords How many active connections to DB am I using? Would it be 3 connections to DB, one for each EJB or only one connection is being used by the 3. All EJBs have Txn attribute "Required".
I think you will have opened 3 physical DB connections. Because each time you call getConnection() you get new connection (connections may be pooled inside container).
I think it would be better close connection before calling another EJB as you can go into deadlock (if container has DB pool). For example, your pool size is 5 connections and you have 2 free DB connection. EJB A calls getConnection(), the EJB B call getConnection(). And when EJB C call getConnection(), this EJB locks locks as DB pool doesn't have any free DB connection (as they č ones are used for EJB A and B). And only some time (pool timeout) this EJB get DB connection error and returns with exception.
So better is to keep DB connection as shorter as possible - read all data, close connection and only then call EJB B if possible.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com