my dog learned polymorphism
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
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

wide use of JNDI, is it a good practice?

raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
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.

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

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.


-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 />
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

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.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Joe Khan

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...
I agree. Here's the link:
subject: wide use of JNDI, is it a good practice?
It's not a secret anymore!