• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stateless session bean test

 
Ravi Singh
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Brian Tinnel
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Prakash Dwivedi
Ranch Hand
Posts: 452
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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).
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic