• Post Reply Bookmark Topic Watch Topic
  • New Topic

Connection Database Growing up non stop.

 
christian leclerc
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guy's ..
I have a stateless session bean that connect to a database to check if a user exist or not and for perform a login.
Well .. everything goes well but the connection to the pool of connection dont stop growing up until the server can't give anymore connection and crash.

this is my code in my EJB :





This is the code of my DS




I just can't figure why the connection dont stop growing up .. now its setup to 6 connections but we try with 50 and this is ain't stop growing up .. ?
My only supposition is because the stateless bean goes in a pool and this pool never destory de bean so the connection ain't close ?
But this will have no sense I think.

Thanks in advance for any help, just got my ejb certification yesterday and im just started to practice it ;) !

Christian Leclerc, CSSLP,OCBCD,SCJP,ZCE


 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My only supposition is because the stateless bean goes in a pool and this pool never destory de bean so the connection ain't close ?
But this will have no sense I think.


It does - get a Connection when you need it - in the userExistInUserWeb(), not in the init() method and close it immediately after use.

cheers,
ram.
 
christian leclerc
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's was it !!
Thanks for the hint.

I was thinking that is a good practice to initiate the connection in the init function but seam that's not a good idea !!


 
Kumar Raja
Ranch Hand
Posts: 547
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to understand the design issue reported in this forum and please correct me If I'm going wrong anywhere.

I agree that having connection acquisition and release, limited to userExistInUserWeb() as in this case, would be beneficiary to make sure connections are used carefully without running out of them. But If we have a transaction that spans across multiple method calls, do we acquire and release the connection in every method. If yes, how do we maintain the transactional state.

I think that container on startup, creates a bunch of beans for pooling, and in the init() , it is acquiring the connection objects for each of those beans and release them on destroy(). As long as the container is able to handle the requests with these beans (supposing that number of beans are lesser or equal to maximum connections allowed), I guess it should be working fine. Since as a developer we can not control the destruction of the stateless session bean and is at the mercy of the container, it is not guaranteed that connection would be ever released and may run into issues like this.

Is my understanding correct ?
 
christian leclerc
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have right.
In a case of a transaction, you should open the connection @ the beginning of the transaction and close it after the transaction.


For a connection you want to put in the @PostConstruct it may work for a Statefull session bean , you close the connection in the @PostDestruct and it will be destroy after the @Remove is invoked.
I think it will be a better approach for a Statefull scenario instead of a stateless bean .


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!