Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt from the Specs

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The below quote is form the specs,

Since stateless session bean instances are typically pooled, the time of the client's invocation of the create method need not have any direct relationship to the container's invocation of the PostConstruct/ejbCreate method on the stateless session bean instance.


I'm failing to understand this. Please help guys!
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jothi

any method from your business interface does not need to relay on the PostConstruct method. Something like one bussines method will fail if the PostConstruct method(s) does not runs before.

I also think that the same logic for the pasivate feature (callback)

Regards,
M
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still coudn't get it!
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See specs paragraph 4.5.1
The stateless session beans are pooled. This means that:
1. You don't know when PostConstruct method is called
2. If an instance of your bean is reused for another client, the callback method will not be called

This means that your PostConstruct invokation cannot safely access to informations related to a specific request.
 
Nitin Takale
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jyoti,

Stateless Session Beans are pooled. So think.. when the instances of bean class are getting created... as soon as you deploy the bean.

Now when you deploy the bean the container how it is creating the instance of bean class that is given to it ???

first it (container) loads the bean class
then it calls.. Class.newInstance() to create the object of bean...
then it calls ... setSessionContext if it is there..
then it calls... any method annotated with postConstruct or ejbCreate if it is there...

now bean pool is ready..

After this (it means after deployment of bean) client is free to call method on bean.

now even if a ejb 2.0/2.1 client... (their home interface has create method).. does lookup on homeObject and then calls create() on that home object (which according to ejb 2.0/2.1 specs is going to return reference of remote / local interface ..) the container is not going to create new bean instance so it is not going to call any postConstruct or ejbCreate method on bean.

That's what the specs is saying.


(There are some other details which you'll get to know later on as you progress)

I hope this is sufficient for you.

bye

nitin
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After a long time I had to go through the specs and now I can manipulate what you have explained above. Thanks!
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But don't anyone feel that the particular paragraph that I posted above form the specs are a bit confusing?
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way is there anyone here who can provide some hints on some App servers that are 100% EJB 3 spec compliant?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But don't anyone feel that the particular paragraph that I posted above form the specs are a bit confusing?

Yes, it may be difficult to understand if you are only used to EJB3's marvelous injection system, because things are done in the background. So "client's invocation of the create method" sounds obscure. If you know about EJB2.X, the way to use home interfaces to create beans, then what's written in the spec becomes clear.
[ September 04, 2008: Message edited by: Christophe Verre ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic