Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Repeated calls of EJB method reaches maximum number of concurrent connections to database  RSS feed

 
Dimitris Karageorgopoulos
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

from a JSF backing bean I repeatedly call an EJB method that makes a call to my Oracle database. This is the operation is general

1. in the backing bean I open a server stored file which usually contains a larger number of lines, e.g. 1000. Each line represents a database Insert/Update/Delete row operation.
2. For each line of the file I call an EJB (Enterprise Java Bean) method which calls a stored procedure on my Oracle database.
3. After a number of lines read (e.g. 128) and subsequent method invocations, the database refuses any more connection to it.

It seems that I reach the maximum number of concurrent connections created to the database, and I am wondering why this happens. I try to figure out where I don't release database resources; in the backing bean or in the EJB method ?

In the EJB method my code creates a CallableStatement object and at the end I close it.

Should I do something in the JSF backing to release database resources after each EJB method invocation ?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Dmitris!

JSF doesn't make a difference here.

I believe it's a violation of the EJB specification for an EJB to open a file. So that's a problem right there. If you're running out of connections to the database, probably the EJB isn't closing them after it's done with them. The preferred way to do things like that is to use a connection pool, which will return the connection to the pool when you close it. You can also open a connection directly, but that's going to be slower and more overhead. And you still have to close it when you're done. Garbage collection won't do this for you.
 
Dimitris Karageorgopoulos
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. Really helpful!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!