• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

EJB opening too many connections to DB

Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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".

Thanks in Advance.

Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
    Bookmark Topic Watch Topic
  • New Topic