• 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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Container or bean provider cleans up resources when system exception occurs?

 
Bartender
Posts: 2442
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quote A says the container will clean up when a system exception occurs:


The bean provider can rely on the container to perform the following tasks when catching a non-application exception:
....
This means that unless the bean is a Singleton, the bean provider does not have to perform any cleanup... It is the container
that is responsible for the cleanup.
JSR 318 p.383.



Quote B says the bean provider/application should do the cleanup when a system exception occurs:


PreDestroy lifecycle callback interceptor method not being called:
...
A system exception thrown from the instance's method to the container.
... The application using the session bean should provide some clean up mechanism to periodically cleanup the unreleased
resources.
JSR 318 p.97



So, are quote A and quote B conflicting each other?
 
Creator of Enthuware JWS+ V6
Posts: 3412
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So, are quote A and quote B conflicting each other?


Not really. The cleanup (on page 97) has nothing to do with the current transaction or the bean that is involved.

They give a nice example of the cleanup they are talking about.

The note on page 97:

For example, if a shopping cart component is implemented as a session bean, and the session bean stores the shopping cart content in a database, the application should provide a program that runs periodically and removes "abandoned" shopping carts from the database.

 
Himai Minh
Bartender
Posts: 2442
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for Frits' reply.
So, on p.318, the container cleans up by logging the exception, rollback the transaction and discarding the bean when the stateless/stateful bean's business , lifecycle callback methods/interceptors throw system exceptions.

On the other hand, on p.97, the bean provider (developer) has to do the cleanup work that the container cannot do, such as closing the database connection, restoring the data in database, which are related to the application itself.
 
She'll be back. I'm just gonna wait here. With this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic