wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes jndi vs hashmap in context 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 "jndi vs hashmap in context" Watch "jndi vs hashmap in context" New topic
Author

jndi vs hashmap in context

poorvika chanda
Greenhorn

Joined: Oct 31, 2011
Posts: 13
hello friends,
one of the uses of jndi is lookup.as an alternative can I use an hashmap with names mapped with object paths and the hashmap stored in application context.
is the both approaches same.
Regards
Poorvika
Abhinav Srivastava
Ranch Hand

Joined: Nov 19, 2002
Posts: 349

JNDI is typically used for looking up resources such as EJBs and DataSources. JNDI API is only an abstraction over the underlying directory (e.g. LDAP).
In a typical ServiceLocator implementation, you do cache looked-up objects in a HashMap. But you still use the JNDI API to access objects first time.

If you application requires to lookup same objects again and again, such as a configuration, it can very well be kept in a global (such as Application Context) HashMap. This HashMap cannot be (directly) looked up from other JVMs, however an object bound to JNDI tree can be looked up from other JVMs also.

poorvika chanda
Greenhorn

Joined: Oct 31, 2011
Posts: 13
things are clear now .thanks .when the objects are required to access from other JVM also it is preferred to bind them via JNDI.Otherwise we can use hashmap objects in application context .am I correct?
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10146
    
165

poorvika chanda wrote:when the objects are required to access from other JVM also it is preferred to bind them via JNDI.Otherwise we can use hashmap objects in application context .am I correct?


The statement that JNDI is similar to HashMap is a overly simplified one, to let beginners get an idea of how JNDI bindings work. However, JNDI APIs are much more than just a Map key value pair. Irrespective of whether your client is in the same JVM or a remote JVM, using JNDI wherever it's applicable (like EJB bindings and such) is the right thing to do.

[My Blog] [JavaRanch Journal]
poorvika chanda
Greenhorn

Joined: Oct 31, 2011
Posts: 13
may I know the main advantage of using JNDI rather than using hashmap stored in application context.one reason I came to know is accessibilty from other JVMS.Any other significant advantage.
 
Don't get me started about those stupid light bulbs.
 
subject: jndi vs hashmap in context