wood burning stoves*
The moose likes EJB and other Java EE Technologies and the fly likes Bad decision to open connection inside PostConstruct and close connection inside PreDestroy? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Bad decision to open connection inside PostConstruct and close connection inside PreDestroy?" Watch "Bad decision to open connection inside PostConstruct and close connection inside PreDestroy?" New topic
Author

Bad decision to open connection inside PostConstruct and close connection inside PreDestroy?

Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
As I've read in EJB books, it suggests to open connection inside PostConstruct and close connection inside PreDestroy.

This is totally wrong decision to implement. Since Stateless Beans are pooled by container, it will open multiple connections and you never know when SSB will be destroyed. By the time it will be destroyed, you will ran out of connections.

In only one scenario it would make perfect sense to use above approach when you balance the numbers between number of pooled SSB's and the number of DB connections that can be opened.

Let me know your thoughts if you have faced same scenario.

SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
Any thoughts on this? I stumbled on this issue again, so came across on my own thread.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Bad decision to open connection inside PostConstruct and close connection inside PreDestroy?