brettwooldridge/NuProcess

Reason for the Synchronized call in `LinProcessFactory`

deepika433 opened this issue · 2 comments

We are currently seeking an alternative solution to the Java ProcessBuilder, which uses a synchronized native call in the ProcessImpl.create method to create processes.

While exploring the NuProcess, we noticed that the Linux implementation includes a static synchronized call in the createProcess method.

Could you help us understand the reason for this synchronized call in the NuProcess implementation?

I don't think I can offer a definitive reason for it, as that block predates my involvement with NuProcess by several years, but the commits link back to issue #6 and some problems with "hanging" when creating processes.

Even if the synchronized block was necessary back then, it's unclear to me whether it's necessary now. When the synchronized block was originally added, NuProcess had its own JNA-based native approach for forking processes, and it was shared between macOS (which didn't, and still doesn't, appear to need synchronization) and Linux. In contemporary NuProcess, though, Linux has been updated to directly call the JDK's own forkAndExec method. That means whatever issue in the previous spawning code necessitated the synchronization, it may no longer be an issue.

With that said, I'm not sure I entirely understand what you're asking. The JDK8 link you provide is to the Windows ProcessImpl, and it is indeed synchronized, but the synchronization in NuProcess you link to is for Linux, and is not executed on or relevant to Windows. As far as I can tell, WinProcessFactory and WindowsProcess do not synchronize when creating processes, aside from briefly while choosing the processor thread to assign the new process to. (If you use run instead of start, there is no synchronization at all.)

Can you clarify what you're looking for, and what your use case is that makes it important to you?

Thank you for the update, @bturner.

We are hoping for a single solution across different OSes, so only we enquired you about the feasibility of removing it.

Could you please elaborate on the differences between the start and run methods in NuProcessBuilder, as I am unable to find information about this in the documentation and javadoc?

Also, if you feel/say that synchronization is not needed, can a new version of NuProcess be released with that removed ?