I have an environment variable that turns a string of comma-separated variables into a List for use in my Java app.
It currently holds a dozen entries and it looks like this:
1234,5678,9012
It works just fine now, and I’ve tested with with 100 items, so the list is just shy of 500 characters, and it works, but what if we need to go to 1000 items?
Is there a max size for Java ENV vars?
I did a fairly thorough search through the google and didn’t find anything.
When your list gets rather large, create a file that you read. Files aren’t character limited.
@GilbertLeBlanc that is an excellent idea, and it will work. I’ll go that route if I need to do so. My concern for the moment is that using a file would require deployment of new file when we update the list so it would be a slower change than modifying the env vars and bouncing the app.
You can pass the file path and name to the app, so you can keep historical versions of the list. You have to restart (bounce) the app anyway.
You could always make a minimal reproducible example and test it for yourself. The relevant limit is probably the operating system’s limit on environment variable size.
Your question cannot be easily answered. There are many layers that affect environment variable size. 1) Some systems limit the maximum of all environment variables. For example, AWS EB limits the total to 4 KB IIRC. 2) Java is affected by the heap size setting. 3) Each OS has its own limitations. My advice: do not use environment variables to pass data. There is no point in designing future bugs.