I am working on an hospital application where i need to show blood group in every second page in drop down and getting values from them to the db tables since blood group are not frequent changing entity so we are planning to create a map with key value pair and make available this map throughout application in order to avid creation of same map multiple time
my question is what can be the best way to achieve this.some of the quick options coming to my mind are
- Create a map at application start up and place it in application context
- Create a utility class which read a property file and fill map with these values or simply create map with exisitng blood type.
but i am not sure how effective these options are as site will have to handle a good amount to user hits in near future.
Gracias por adelantado
preguntado el 08 de noviembre de 11 a las 15:11
Create a utility class that loads these values on system startup or load values when the class loads. Creating a class this way would give few advantages:
- You can test this class and its functionality by writing test cases for this class. (Check if things are loading properly etc)
- This makes you less dependent on the context and how the context works. Makes your application less troublesome to move if you, for some reason, need to change application server.
- Code becomes more readable (
BloodGroupUtils.getAll()en comparación con
Application.getContext().get("bloodGroups");o algo similar.)
On Performance, this may be a bit faster. Not necessarily though ( we would need to check several other system usage/parameters to come to that conclusion.)
Retrieving the values from a static class or the application context will have essentially the same performance. The static class might be trivially faster as you don't have to get the map out of the application context, but I can't imagine it'd be worth worrying about.