Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to share variable between processes in Java with Process Builder

Original message

I'm currently working on several executable Jars being called by another Java process (or "Launcher) called by a scheduler.

To do this, we use ProcessBuilder. However, we need to be able to share variable between the parent process and the child process (The executable JAR).

I know it's possible to pass variable to the child process with the environment() method.

What we need is to be able to share informations from the child process to the parent process (the process results, mostly files). Is it possible? If it is, how so?

Update The two java processes are on the same computer and so share the same disk space. The Launcher process is called by a scheduler and this process cannot be changed.

I know that using a file is probably the best solution but I was wondering if there was no other solution.

Thanks in advance for your help.

like image 213
qbisson Avatar asked Jun 19 '26 10:06

qbisson


1 Answers

A process is a sort of black box with which you can dialogue only via standard streams (input, output, error) or retrieving exit code of the process. All other systems needs an external way to communicate.

So you can:

  • Use the method exitValue() of the Process as a form of communication between child and parent.

  • Intercept the output of the child process using the getInputStream() method.

  • Share data with external resources (files, databases or opening communication sockets for example).

like image 125
Davide Lorenzo MARINO Avatar answered Jun 22 '26 01:06

Davide Lorenzo MARINO



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!