This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt from Spec

 
Shanmugam Karthikeyan
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have just started preparing for SCBCD.I am currently going through the EJB spec.

In the spec in the following paragraph i have a doubt (page 66)

" All session objects of the same stateless session bean within the same home have the same object identity,which is assigned by the container."

Here in the above statement i have the following doubts.

1. I am i right to say that "All session objects" means "All EJB Objects" ?If what i have understood is right then according to Head First each client gets his own EJBObject and his own bean.

So it means that if there is client A, then that client A will get EJBObject A and a bean A and for client B an EJBObjectB and a bean B.

so when we use isIdentical() method for checking whether two EJB Object is refering to the same bean it should result false always.But in the spec i found the following line which confuses me.

"The following example illustrates the use of the isIdentical method for a stateless session object.

FooHome fooHome = ...; // obtain home of a stateless session bean
Foo foo1 = fooHome.create();
Foo foo2 = fooHome.create();
if (foo1.isIdentical(foo1)) {// this test returns true
...
}
if (foo1.isIdentical(foo2)) {// this test returns true
...
}"

My question is how in the second if statement the test returns true ?
If i have understood wrongly , pls correct me.
 
Ramakrishnan Viswanathan
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For stateless beans, the bean-client association happens only during a business method invocation. When an isIdentical() operation is performed, although the client can assume that it is comparing two EJBObject instances, the actual implementation (which is vendor independent) would just result in a comparison of their respective EJBHome-s.
 
Shanmugam Karthikeyan
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your reply.

Did you mean to say that for a stateless session bean, The isIdentical method compared the Home Object rather than the EJBObject since the EJBObject is create only when a client invokes the business method ?


So in this case it will always return true because a single Home Object
will be created and shared no matter how many EJBObject or session bean instances are created.
 
Ramakrishnan Viswanathan
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is the container's discretion whether to create one or two EJBObject(s). And each container may do this differently, so this is purely a vendor implementation. There is no guarantee that you have 2 instances created from the same home. What is guaranteed is that calling isIdentical() would return true no matter how the container handles the creation. So you wouldn't really have to know whether the server created two different objects or is just using one.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic