Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jndi vs hashmap in context

 
poorvika chanda
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 354
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
poorvika chanda
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic