0

I have a javax rest service that needs to retrieve data from an object database. Additionally, it always needs to perform a lookup in a table (key is a string, value is an integer). There are 250 values in the lookup table, which I am currently accessing and choosing from, using a "normal" database query. The values never change, so access can be purely read-only based.

What would be the fastest way to achieve this lookup ? I thought of either a static map that belongs to the service's class (hard-coded) or a file on the server's file system. I must admit that I don't fully understand the memory allocation model (static/non-static) when the rest service is invoked, and to what extent things like the static keyword have an influence on, or override things - which, I suppose, would have an impact on what the ideal tradeoff between speed and memory consumption is.

Hiro Protagonist
  • 474
  • 3
  • 15
  • That has little to do with the "service" aspect. You decide based on memory, refresh constraints, caching, and distributed nature of your service. You can easily have a static Map variable that you read in a service method, that wouldn't make a difference as far as the service is concerned... – ernest_k Apr 20 '18 at 13:15
  • @ErnestKiwele I am just wary of "1000 calls = 1000 copies of the map *despite* having declared it to be static". Although.... at 250 entries, even that'd probably be negligible. – Hiro Protagonist Apr 20 '18 at 13:27
  • 1
    A `static` field will be maintained only once per class loader (almost per VM). Of course the value will be read/copied for the client on each request that accesses it. It could also be that you have one map that service methods search, to return just subsets of the data – ernest_k Apr 20 '18 at 13:48

0 Answers0