aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Stateful session bean calling @remove method from client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Stateful session bean calling @remove method from client" Watch "Stateful session bean calling @remove method from client" New topic
Author

Stateful session bean calling @remove method from client

Lalit mishra
Ranch Hand

Joined: Sep 01, 2005
Posts: 99
Hi all,
How do we call the @remove method from ejb client. A code snippet would be a great help.

Thanks,
Lalit
Sai Surya
Ranch Hand

Joined: Feb 08, 2006
Posts: 457

Lalit mishra wrote:Hi all,
How do we call the @remove method from ejb client. A code snippet would be a great help.

Thanks,
Lalit


Hi Lalit,

We will call any method of Statefull session bean in the normal way (like POJO) The only thing is, method is marked with @Remove annotation in order to indicate the container that workflow ends after calling this method. Once method with @Remove executes the container will remove the Stateful bean instance.

Hope you understood.


Sai Surya, SCJP 5.0, SCWCD 5.0, IBM 833 834
http://sai-surya-talk.blogspot.com, I believe in Murphy's law.
SampathKumar chinnadurai
Ranch Hand

Joined: Jul 05, 2006
Posts: 44
Hi Lalit,

We can't directly call the @Remove annotation from EJB client .we have to call the @Remove tagged business method from the client.

The @Remove annotation is used with a method to inform the container that the client no longer needs a session and that the session should be destroyed. This annotation is important, as it is the only way to request the container that the session should end. If the remove method is not used, the session will have to be timed out before it can be destroyed by itself. If stateful session bean instances are not removed when they are no longer needed, the number of inactive instances will keep on incrementing and will waste memory and CPU cycles. The syntax for declaring a method with the @Remove annotation is as follows:


Cleared SCJP 6 (87%), SCWCD 5 (94%), SCBCD 5.0(95%), PMP ,preparing SCDJWS ,OCUP
Lalit mishra
Ranch Hand

Joined: Sep 01, 2005
Posts: 99
Thank you guys
Vivek Punekar
Greenhorn

Joined: Aug 25, 2009
Posts: 12
I am doing exactly this. Calling the @Remove and @Destroy annotated method from client but still I can see the SFSB hanging around in JProfiler.

I will highly appreciate any help, suggestion.

Thanks.
Vivek Punekar
Greenhorn

Joined: Aug 25, 2009
Posts: 12
BTW, I have also tried nullifying the EJB reference. Still it doesn't work.

Thanks.
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi

As far as I know this measure makes the bean eligible for garbage collector, this does not means that the bean is also "garbeged" on the moment.
In most of the times the profilers have some ways to force the cg to occurs - but this is to profiler specific.

Regards
M


SCJP, SCJD, SCWCD, OCPJBCD
Vivek Punekar
Greenhorn

Joined: Aug 25, 2009
Posts: 12
Thanks for the reply.

I did use the force GC option on Profiler but it still doesnt cleanup the bean.

Thanks,
Vivek

Vivek Punekar
Greenhorn

Joined: Aug 25, 2009
Posts: 12
In fact I tried creating so many instances of the EJBs and everytime calling the @Remove method. Hundreds of instances were created and the server went OutOfMemory finally. But still the EJBs were hanging around.

Any clues?

Thanks in advance.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9993
    
    7

Vivek JavaRancher wrote:


Please check your private messages for an important administrative matter.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Vivek Punekar
Greenhorn

Joined: Aug 25, 2009
Posts: 12

My mistake. I had not deployed the changes correctly. Calling the method with @Remove does remove the EJB and its fundamentally correct.

Whats the difference between @Destroy and @Remove? Are both of them needed for Seam component which is an EJB as well?

Thanks.
nitin pokhriyal
Ranch Hand

Joined: May 19, 2005
Posts: 263
If i am not wrong then

For @remove see comments above of SampathKumar chinnadurai
for @Destroy : Specifies that the method should be called when the context ends and its context variables are destroyed. Note that create methods are only supported for JavaBeans and stateful session beans.
Note that all stateful session bean components must define a method annotated @Destroy @Remove in order to guarantee destruction of the stateful bean when a context ends.
Destroy methods should be used only for cleanup. Seam catches, logs and swallows any exception that propagates out of a destroy method. Looks to me that either container removes bean or by @remove on method both calls destroy for cleanup.

anybody correct me if i am wrong.
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi

Is @Destroy is a ejb annotation ? I am afraid that this is something jBoss specific.

Regards,
Mihai
nitin pokhriyal
Ranch Hand

Joined: May 19, 2005
Posts: 263
My bad. yes you are correct it is in Jboss seams
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi

Yes, this is true, Seam has a @Destroy - life cycle callback.

Regards,
Mihai
Vivek Punekar
Greenhorn

Joined: Aug 25, 2009
Posts: 12
Hello,

So does it mean we need both @Remove and @Destroy for a Seam component which is EJB also?

Thanks,
Vivek
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi.

That's depends what are you doing.
I tend to answer no to this question.
The @Remove cleans marks the ends of a stateful bean.
The @Destroy is jBoss/seam specific and it represents the finalisation for a seam component. More precisely before the seam component (which is a bean) pull out from the context this method is call.

Regards,
Mihai
Klaus Schultz
Greenhorn

Joined: Aug 29, 2009
Posts: 15
Taking beside Seam: in EJB you should differentiate between the concept of a @Remove annotated method of stateful session bean, which will be called by the client, and the concept of a @PreDestroy annotated method, a lifecycle callback method called by the container. I think the Destroy method of Seam resembles the PreDestroy in EJB.

Klaus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stateful session bean calling @remove method from client
 
Similar Threads
Why so many remove()
Stateful bean and instance pooling
HFEJB final Mock Question
ejbRemove??
Please Answer.