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.
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...)
> 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?
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.