Hi there,
I am a newbie to Java programming and would like to get some feedback on how I can proceed with a problem I have at hand. I have to maintain the objects information in the memory for a SITE. SITE has side id, site name, and a site will be related to devices (one or more devices). Devices will have information such as is it alive what is the frequency of its alive signal coming to the server. These information have to be in-memory all the time so that at any point of time I would have to pick the device alive signal and process the neccesary tasks such as send an email to user whose device is not working. (email information for each device as well will be maintained in the memory). What kind of data structure can I use to acheive this scanerio. I was thinking of HASHTABLE but I am unable to get any samples that can explain the HASHTABLE usage. If anyone could help me in getting the right information it will be really helpful.
Thanking you in advance
regards
John
Lars-Inge T?nnessen - 14 Jun 2004 17:39 GMT
Here is a hash table example I wrote for you. Please remember hash tables perform best when they are approx 75 % full.
In Java (and J#), please use the .GetHashCode() method to return the hash key for the objects.
If you want to allocate more space in runtime, please use the rehash() method on the hash table.
Sorry I can't give more advice on the arcitecture, as I don't have the details.
public class hello
{
public int number = 0;
public hello( int numb )
{
this.number = numb;
}
int retnumb( )
{
return this.number;
}
}
public class Class1
{
public Class1()
{
System.out.println("Start");
java.util.Hashtable hash = new java.util.Hashtable(100);
hello one = new hello(1);
hello two = new hello(2);
// key object
hash.put( new Integer( one.GetHashCode()), (Object)one );
hash.put( new Integer( two.GetHashCode()), (Object)two );
// key
hello got = (hello)hash.get( new Integer( one.GetHashCode()) );
System.out.println("Got :"+got.retnumb() );
System.out.println("End");
}
/** @attribute System.STAThread() */
public static void main(String[] args)
{
new Class1();
}
}
Regards,
Lars-Inge T?nnessen
www.larsinge.com