Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confusing Question/Answer

 
Vinay Nath
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a system exception happens ina bean and its holding resources, who is responsible to release resources?

the answer says, its container's responsibility but I think its neither container's nor bean provider's responsibilty because container just logs the error, rollback/mark transaction, discard the instance and wrap exception into EJBException and throw it back to client. It doesnt even call preDestroy method so Bean provider's responsibility also goes out of question.

Am I wrong or right?
 
Vinay Nath
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anybody???
 
Nikhil Jain
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am too confused on it. But when I tried the same, on JBOSS, the predestroy method got executed. But the spec says that Pre-destroy may not be called.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is the container providers's role to release managed resources in this situation, when discarding the bean instance. Of course, unmanaged resources cannot be dealt by the container.

In the core specification, about the bean provider's responsability for system exceptions (14.2.2 System Exceptions), it is stated that the Bean Provider does not have to perform any cleanup actions before throwing a non-application exception. It is the container that is responsible for the cleanup.

You'll find even more details at the "14.3.11 Release of Resources" section, about the Container's responsability : When the container discards an instance because of a system exception, the container should release all the resources held by the instance that were acquired through the resource factories declared in the enterprise bean environment (See Subsection 16.7).
Note: While the container should release the connections to the resource managers that the instance acquired through the resource factories declared in the enterprise bean environment, the container cannot, in general, release �unmanaged� resources that the instance may have acquired through the JDK APIs. For example, if the instance has opened a TCP/IP connection, most container implementations will not be able to release the connection. The connection will be eventually released by the JVM garbage collector mechanism.
 
Vinay Nath
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help guys!!!

I hope in real exam, the questions will be much more specific, like managed-unmanaged resources.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic