Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stateful session bean calling @remove method from client

 
Lalit mishra
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 463
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
SampathKumar chinnadurai
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Lalit mishra
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys
 
Vivek Punekar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, I have also tried nullifying the EJB reference. Still it doesn't work.

Thanks.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vivek Punekar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vivek JavaRancher wrote:


Please check your private messages for an important administrative matter.
 
Vivek Punekar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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

Regards,
Mihai
 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My bad. yes you are correct it is in Jboss seams
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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

Regards,
Mihai
 
Vivek Punekar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic