The Artima Developer Community
Sponsored Link

Design Forum
Lookup table - help please

4 replies on 1 page. Most recent reply: Sep 26, 2003 2:12 AM by Desmond Cheng

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Michael

Posts: 4
Nickname: yaruki
Registered: May, 2003

Lookup table - help please Posted: May 21, 2003 5:53 AM
Reply to this message Reply
Advertisement
I need to implement a class to essentially become a huge lookup table (12k entries) - I feed it a "key" and it returns a value. Right now the code is being run as part of a standalone/GUI app, but as I will eventually make it a servlet, I'm more concerned with performance of the lookup than with slow initialization times.

1) What is the best way to do this - just build a big (static) HashMap?

2) To initialize it, I'm planning on loading the data from a tab-delimited text file at runtime - is this wise? I'm a little confused about where that file should live and how I should point my class to it. Is it better to initialize all the data in a static block so it's compiled in?

3) Related to the previous point, this class will be packaged in a jar that is one of several jars to be passed in through the command line classpath to launch the application. I don't really understand how the "virtual filesystems" represented in multiple jars relate to each other, and what kind of views of the various namespaces are available to classes in the various jars. How can I best package up the initialization data text file into one of the jars and then find it again at runtime to load the data?

Please enlighten me or point me at some resources where I can learn more about these sorts of things. Any assistance at all would be greatly appreciated.

Thanks!
Michael


zenykx

Posts: 69
Nickname: zenykx
Registered: May, 2003

Re: Lookup table - help please Posted: May 25, 2003 1:50 PM
Reply to this message Reply
It is not a general solution for this problem. Maybe you can create a lazy loading/retrieval mechanism for the HashMap in order to minimize the memory impact.

For the file retrieval you can use some kind of JNDI lookups with filesystem provider.
You must find the fsprovider.jar from SUN (sorry i do not find this info right know...)

Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: Lookup table - help please Posted: Sep 1, 2003 3:41 PM
Reply to this message Reply
If all the keys are unrelated, yes there is not much choice...
Otherwise having groups of Key-values is an option.

I prefere Properties (Property files) as I have it easier to support them !

Yes in the jar, directly should be fine ...
What is exactly your problem with that... ?

\T,

Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: Lookup table - help please Posted: Sep 22, 2003 8:42 AM
Reply to this message Reply
Without knowing very much about your application, I would first try the simplest possible solution.

Create an instance variable of type
java.util.Properties
in your servlet. Initialize the variable in the
init()
method of the servlet, passing it the name of the properties file.

The web application, by default, will have only one instance of the servlet in memory, and thus only one instance of the properties object.

Desmond Cheng

Posts: 2
Nickname: siufu
Registered: Sep, 2003

Re: Lookup table - help please Posted: Sep 26, 2003 2:12 AM
Reply to this message Reply
> 3) Related to the previous point, this class will be
> packaged in a jar that is one of several jars to be passed
> in through the command line classpath to launch the
> application. I don't really understand how the "virtual
> filesystems" represented in multiple jars relate to each
> other, and what kind of views of the various namespaces
> are available to classes in the various jars. How can I
> best package up the initialization data text file into one
> of the jars and then find it again at runtime to load the
> data?

Hi,

I would like to suggest that you take a look at

java.lang.Class#getResourceAsStream(java.lang.String)

This method search classes and jars in your classpath and returns an java.io.InputStream instance for the resource (say, your tab-delimited text file) found.

After that, call the following method

java.util.Properties#load(java.io.InputStream)

to fill in a properties instance.

Flat View: This topic has 4 replies on 1 page
Topic: Design issue - how to list options on a page to maximize clarity for user Previous Topic   Next Topic Topic: Site to work faster

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use