Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

jndi vs hashmap in context

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 354
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic