Answer the question
In order to leave comments, you need to log in
How to initialize variables once in a method in Rest web service in Java?
There is a simple web service on jax-rs. It implements two web methods. Both methods in their work before executing some algorithm read the settings from the file and then use these settings.
The question is how to make the settings read once and saved, for example, in some one static variable, and not to read the file each time the web method is called?
Answer the question
In order to leave comments, you need to log in
Depending on what your services are based on. If through servlets, then save the settings to the application or servlet context. If on some fashionable framework like spring, sparkjava or jooby, then design the class as a module, synton or service. In any case, you can make a singleton, just do not forget about synchronization and multithreading. Questions, after googling, ask in the comments.
java-online.ru/servlet-context.xhtml
https://habr.com/post/129494/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question