java object reference index..

Hi All,

I have two doubts, it will be great if I could be suggested any thing on these.

1. Is it a good idea to create an java object in the memory, may be 1-2 Mb in size and keep it in the server for a long period? The reason is the server restart may be once in 50-60 days.

2. If the component objects(child objects... you can think of the whole object as a XML file structure), of the above mentioned object, are having a unique attribute id (type String), can I genereate an index on this attribute that will give me the reference of the object, so that I do not have to traverse the entire object to get an child object having a unique id.

Can you suggest any algorithm (number of child objects / items in the index will be 80000 - 100000) like binary indexing or hash function etc..

where in I will search the index with an unique ID (String type) and get a Object reference.

TIA

Ayusman

[942 byte] By [ayusman_dikshita] at [2007-10-3 11:47:00]
# 1

> 1. Is it a good idea to ...

Based on the information you gave, it is impossible to access whether it is a good idea or bad idea. If your computer has infinite CPU and infinite memory, then it wouldn't matter if you kept 1-2 MB in memory. It comes down to 1) how much time would it take to load that information from disk 2) how much time is the end user / process that depends on the information willing to wait 3) what other resources would be competing for that memory 4) how often would that memory be accessed, in other words, what is the gain / loss of not having it in memory vs the gain / loss of having it in memory.

> 2. If the component objects(child objects...

A hashtable would provide one possible solution. If your tree structure is likely to grow into 10s or 100s of MBs, then you may want to use a database. XML in my opinion is more of a transitional state of storing information (e.g. when the information needs to be transfered). I don't think storing a XML tree in memory is a good idea because it may not lend well to writing code to gather information.

rkippena at 2007-7-15 14:19:52 > top of Java-index,Other Topics,Algorithms...
# 2
1: If you decide to keep your object in memory. I would probably use a SoftReference, so your object will be collected (by the gc) if free memory is really needed.
Domi27a at 2007-7-15 14:19:52 > top of Java-index,Other Topics,Algorithms...
# 3

Hi,

thanks for your response.

The machine I am plannig to keep the object in memory is a OS X server, and though it will not have infinite memeory, when I tried doing it on a windows desktop it was working well.

Why I want to go for this approach is: I have only one option left apart from this; to access the XML file on hard disk that has been source of my Java Object.

Your suggestions will be valuable to me in over all design of my application.

TIA

Ayusman

ayusman_dikshita at 2007-7-15 14:19:52 > top of Java-index,Other Topics,Algorithms...