Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating remote object in init  RSS feed

 
Nijeesh Balan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a basic doubt in Stateless Session Bean. Can i create both Home and Remote interface objects in the init() method of the servlet.. Will it create any problems.
As of now we are looking up for the home object in the init() method and
creating the remote objects in doPost() method of the servlet.
Which is the best way to do it? Plz clarify.
Thanks in Advance,
Nijeesh.
 
Kirt Henrie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are creating your remote interface in the init method you must be keeping it as an instance variable in the servlet. While you will probably be OK doing that you are not allowing the container to effectively manage the bean pool, as this reference will not often go out of scope. I would recommend looking up the home interface in the init method but creating the remote interface upon demand. More than likely you will be getting the same instance either way, unless the container determines the need to create another instance.
Another suggestion would be to cache your home interface in a singleton class, this will insure you only have one instance for best performance.
As you may know, the biggest performance hit is in the JNDI lookup and narrowing of the home interface.
KJ
 
Nijeesh Balan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply kirt.
The problem here is if i create a remote object during each method call to the servlet(in doPost method) then is it not an unnecessary call over the n/w.
Instead if the remote object is an instance variable this call can be avoided.
Plz correct me if I'm wrong.
Thanks in Advance,
Nijeesh.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!