wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes When to use jndi ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "When to use jndi ?" Watch "When to use jndi ?" New topic
Author

When to use jndi ?

Mark Uppeteer
Ranch Hand

Joined: Mar 02, 2004
Posts: 159

Hello,
I have a question about the use of jndi.
Is it made only to e.g. lookup of beans , can we compare it to the windows registry ? ->as in : its there, it works but its not good programmoing to go and use it extensively.
or
is it frequently used as a place to store "global" objects in memory ?
I'm actually looking for a solution to cach data in a way that it has the same benefits of a entity bean (everyone can access the same data) but I don't want to make it persistent.
Our first solution was to put it in an entity bean as non persistent data, but then when the bean passivates, you lose your non persistent data
What can a person put in jndi and is still good programming ?
thnx


I know where my towel is. (SCJP 5, OCPJWCD)
[Free Quiz Tips for a fun night with friends or family] Flash games
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi Mark,

is it frequently used as a place to store "global" objects in memory ?

NO. JNDI is a "directory service" its not a "cache" maintaining service for objects.
So I guess your dilema of whether to use JNDI for caching gets resolved.
Regards
Maulin
Mark Uppeteer
Ranch Hand

Joined: Mar 02, 2004
Posts: 159

Hello Maulin,
So...can we use it for anything ? if so, can you give an example ?
or is it just to put and search our beans in ?
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi Mark,
Well, it can be used to store anything but that anything is restricted to what "directory services" defines
Google on directory server/services and see what they usually do. They usually store information about resources within an organization like Users, Printers etc in a central place.
What you seem to refer is "caching of objects". If you mean you want to cache number of objects via JNDI (storing it in directory service), that can't be done. We should not get confused between totally different concepts here.
I guess googling on "naming and directory" service or Sun's JNDI tutorial would help you identify what I am babbling....
Thanks
Maulin
Mark Uppeteer
Ranch Hand

Joined: Mar 02, 2004
Posts: 159

thnx for your reply Maulin,
I read a bit about naming and directory services, its sort of a phonebook with name and an object reference 'lines' in it right ?
So in this example...
// Create the object to be bound
Fruit fruit = new Fruit("lemon");
// Perform the bind
ctx.rebind("favorite", fruit);
If fruit goes out of scope, will it be deleted ? or will it stay to exist because jndi still points to it ?
My guess is it will be deleted and your reference will be invalid.
Or am I still missing the ball completely wrong..
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
yup. you have got it
Regards
Maulin
Mark Uppeteer
Ranch Hand

Joined: Mar 02, 2004
Posts: 159

Or am I still missing the ball completely wrong..

thats an interesting sentence :roll:
But then, is there a way (or a solution/pattern) to have an entity bean with none persistent data (for speed reasons) that everyone can access and that doesn't lose its data on passivation ? something like a stateful session bean with multiple users ?
grtz
Mark
Kiran Kumar
Ranch Hand

Joined: May 18, 2001
Posts: 107
Hi,
You can bind a instance of a class(POJO-Plain Old Java Object) to the JNDI context and the client will be able to lookup the same instance from JNDI.

hope this helps.


Thanks<br /> <br />Kiran <br /> <br />SCEA, SCJP 1.4,<br /> <br />"First they ignore u, then they laugh at u, then they fight u, <br />then u will win<br /> <br />Mahatma Gandhi"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When to use jndi ?