This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes wide use of JNDI, is it a good practice? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "wide use of JNDI, is it a good practice?" Watch "wide use of JNDI, is it a good practice?" New topic
Author

wide use of JNDI, is it a good practice?

raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
Hi
Thank you for reading my post.
I want to know that using JNDI to store objects in our application is a good practice or not?

i mean in runtime we create an object and a name for it and bind it into the JNDI.

Thanks
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Using JNDI for this is a good practice, except when it is not a good practice. So, as long as you're doing it while it's a good practice, you're okay. Just don't turn it into a bad practice.

When is it a good practice? When no other options make sense. When is it a bad practice? When there are other options that make more sense.

What is a typical scenario? In a web based application, the ServletContext is a much better scope than JNDI, in my opinion. Is this object shared by all applicaitons, or is it just used between Servlet/JSP invocations. If the object is so important, why isn't it exposed as a web service, so it can be used outside of your domain?

So, there are many options. If we had more details about your scenario, or what other options you have choses, we could probably pass more judgements on your solution.

Cheers!

-Cameron McKenzie
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

what kind of java object you want to store? Give us a scenario which will help us to understand your problem and give a better solution.


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

I think a simple statement like.

Don't put it into the JNDI tree unless you have no other options. Back in the old days of EJB 1.x, this was a common practice of putting things there, but with Contexts, Sessions, Class variables and the goal of POJOs versus Enterprise objects, there are more common better practices, but when all else fails, then maybe think of the JNDI tree. Personally, I leave it to the container to put the objects it thinks should go in there and never put anything in JNDI, but maybe a Cache instead.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Joe Khan
Greenhorn

Joined: Aug 27, 2004
Posts: 15
JNDI is fairly straightforward and easy to use but I think there are disadvantages to JNDI
- JNDI may be a bit slower. There is need for a map lookup
- No strong typing. This can lead to maintainence problems and uglier code.


All things are difficult before they are easy...
 
Don't get me started about those stupid light bulbs.
 
subject: wide use of JNDI, is it a good practice?
 
Similar Threads
is it good practice to initialize a ConnectionFactory in a servlet and save in JNDI?
Explain why this IS working(RAD 7 +EJB 2.1)
can we insert datas in to the database using stateless bean??
JNDI on the desktop
where to put critical cleanup things for stateful session bean?