What is a better way to change variable in runtime server?

272 Views Asked by At

We maintain our server once a week. Sometimes, the customer wishes that we change some settings which is already cached in server. My colleague always write some JSP code to change these settings which are stored in the memory.

Is it a good method to use this kind of methodology? If our project is not a Web container, which tools can help me?

2

There are 2 best solutions below

0
Mark Bramnik On

Usually, in my experience, the server configuration is not stored only in memory of server:

  • What happens that after a configuration change, the server has been restarted / just went down for some system reason?
  • What happens if you have more than one instance of the same server to work on (a cluster of servers in other words)?

So, usually, people opt for various "externalized configuration" options that can range from "file-based" configuration + redeploy the whole cluster upon each configuration change, to configuration management servers (like Consul, etc.d, etc). There are also some solutions that came from (and used in) a java world: Apache Zookeeper, Spring cloud config server to name a few, there are others. In addition, sometimes, it's convenient to store the configurations in a database.

Now to your question: If your project is not a web container and you don't care that configuration will "disappear" after a server restart and you're not running a distributed cluster of servers, then, using JSP indeed doesn't seem appropriate in this case.

Maybe you should take a look at JMX - Java management extensions, that have a built-in solution so that you probably will be able to get rid of a web container (which seems to be not used by your team anyway other than for JSP modifications that you've described).

0
Ori Marko On

You basically need in memory cache, there are multiple solutions found in answers which include creating your own implementation or using existing java library. You can also get data from database and add cache over the database layer.