About Question enthuware.oce-ejbd.v6.2.591 :

Moderator: admin

Post Reply
Pan Niedxwiedx
Posts: 3
Joined: Tue Jul 02, 2013 1:14 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.591 :

Post by Pan Niedxwiedx »

I think that third answer is correct as well:

Acquire the resources in @PostConstruct and @PostActivate and release them in @Remove and @PrePassivate.

If @Remove is called - it will clean up resources.
If @Remove is not called bean will eventually time out and @PrePassivate method will execute, and cause resource cleanup.

Am i wrong?

Pan Niedxwiedx
Posts: 3
Joined: Tue Jul 02, 2013 1:14 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.591 :

Post by Pan Niedxwiedx »

I've thought it through one more time, and after considering container shoutdown i think that second answer is the only one correct.

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.591 :

Post by himaiMinh »

The question mentions that passivate/activate of a bean happens from time to time.
Is it more efficient not to clean up and restore in @PrePassivate or @PreDestroy ?

If passivate/activate happen very frequently and clean up/restore happen as frequently, it is time consuming.
Can we leave the resources open during a bean's passivation, so that the resources are still available after the bean is activated again?

admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.591 :

Post by admin »

It depends on what you want to clean up. If cleaning up a resource takes a lot of time and if the resource is not required by other beans, then you may decide not to clean up at all.
If you like our products and services, please help us by posting your review here.

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.591 :

Post by himaiMinh »

According to p.71 of JSR 318, session 4.2,
a session object's conversational state may contain open resources, such as open sockets and open database cursors. A container cannot retain such open resources when a session bean instance is passivated. A developer of a stateful session bean must close and open the resources in the PrePassivate and PostActivate lifecyle callback interceptor methods.
I think the option about cleaning up in @PreDestroy and @PrePassivate is correct.

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.591 :

Post by himaiMinh »

For the explanation in option 1 :
You need to release the resources when the bean is passivated as well.
The specification does not mandate that resources need to be released in PrePassivate.

admin
Site Admin
Posts: 10053
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.591 :

Post by admin »

The whole purpose of PrePassivate call back is to give the bean an opportunity to release resources before the bean is passivated. The quote from specification that you quote above says that as well.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 34 guests