简体   繁体   中英

Java set persistent environment variable

I have set environment varible through

System.setProperty("mykey" : "itsvalue");

I am retrieving it as :

System.getProperty("mykey");

I get the mykey retrieved properly, but when I restart my service, mykey also get erased. How to save the mykey so that it remains persistent even after service restart?

I don't want to save it in database or cache.

If you just store key value pairs java already has api for this purpose.

You can use preferences API to store key value pairs.

https://www.javaworld.com/article/2071328/the-preferences-api.html

If you have lot of entries better use Database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM