My question is:
Do changes in ProcessBuilder environmental variables or working directories have an effect on PREVIOUSLY spawned processes? Simple tests on Debian 9 and Windows 7 suggest that there's no effect on already created processes, but I'd like to be sure that it is the expected behaviour, preferably having some link to official docs or some explanation about the internals of ProcessBuilder which makes that statement unnecesary.
Details:
I'm using Process Builder in a concurrent system to spawn instances of the same process with different environment variables and working directories from multiple threads.
I'm currently using a ProcessBuilderControler class which avoids the typical concurrency problems by synchronizing the access to PB in order to avoid problems like the following when T1 and T2 attemp to spawn a process at the same time:
In this case, T1 and T2 processes would have spawned scripts with /dir2 as working dir.
My concern was that MAYBE if you changed pb directory even after the process is spawned, the process would get the latest value. This was not the case in windows or linux according to my tests in which I forced the described situation..
No, it is a general limitation of the OS's that you cannot change the environment variables and the working directory of a running process from outside the process.
It might be possible using debugging APIs, but that is certainly not something ProcessBuilder
would do.
I'm currently using a ProcessBuilderControler class which avoids the typical concurrency problems by synchronizing the access to PB in order to avoid problems
The correct way to avoid concurrency problems, when using ProcessBuilder
in a controller class, would be to not use a shared instance of ProcessBuilder
.
That is actually a general recommendation: Don't use shared mutable objects in controllers.