Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Stateless session bean test

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I executed the following code as a stateless session bean test:

InitialContext ctx = new InitialContext(); // Get initial context
CaseEJBHome home = (CaseEJBHome)ctx.lookup("CaseEJB"); // Lookup home
caseEJB = home.create(); // Create stateless session bean

caseEJB.remove() // Remove newly created stateless session bean
caseEJB.remove() // Remove again, the newly created bean

I was expecting the second remove statement to throw an exception as the session bean has previously bean removed but it doesn't.

Is there any reason why no exception is thrown?
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The remove of a Stateless Session Bean acts like a NOP. It doesn't really do anything. Therefore, you can call it as many times as you like and nothing should happen.
 
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Brian Tinnel:
The remove of a Stateless Session Bean acts like a NOP. It doesn't really do anything. Therefore, you can call it as many times as you like and nothing should happen.



So you want to say that if i call business methods on a Stateless Session Bean, after invoking remove() method, it will work?
 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Prakash,

Yes, it will work.

As Brian mentioned EJBObject#remove() call on a stateless session bean's component interface will not anything or in other words a remove() method will not be invoked on the actual SessionBean. It is up to the container to remove a stateless session bean from the pool.

As you might know a component interface is not linked to a particular instance of a stateless session bean. When a client calls a business method on the comp interface, container gets any bean of this type from the pool and invokes a method (i.e. a method invoked by a client on the comp interface) on it. As soon as the method is completed container returns the method result to the client and places the bean back to the pool.

Hope it helps,

 
Prakash Dwivedi
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Alex,
I just tested it on OC4J and its working
[ September 16, 2004: Message edited by: Prakash Dwivedi ]
 
Ravi Singh
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alex,

I thought invoking the create() method for a stateless session bean created an ejbObject for the client on the server, and then when the client invoked a method a bean from the instance pool was 'swapped' into the ejbObject of the client and serviced the request before being placed back into the instance pool?

Then when you invoke remove(), it is the 'ejbObject' which is removed.

Or is this just a conceptual view of things?
 
Brian Tinnel
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess you can think of it that way, but it isn't accurate and that could cause some errors in your code because your concept does not match reality. The danger in not knowing how a bean really works is that you might use an instance variable to not realize that when you store data in it, that data is available to any client which happens to get the same bean instance.

So it is important to know that a remove does not really remve anything, and that a create really doesn't create anything (from the standpoint of a Stateless Session Bean).
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic