Page 1 of 1

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

Posted: Tue Jul 02, 2013 1:26 pm
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?

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

Posted: Wed Jul 03, 2013 12:58 pm
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.

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

Posted: Sun May 03, 2015 6:41 pm
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?

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

Posted: Sun May 03, 2015 10:26 pm
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.

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

Posted: Mon May 04, 2015 12:11 pm
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.

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

Posted: Wed May 06, 2015 5:49 pm
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.

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

Posted: Wed May 06, 2015 6:52 pm
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.