Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reason for the Synchronized call in LinProcessFactory #159

Open
deepika433 opened this issue Jul 22, 2024 · 2 comments
Open

Reason for the Synchronized call in LinProcessFactory #159

deepika433 opened this issue Jul 22, 2024 · 2 comments

Comments

@deepika433
Copy link

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?

@bturner
Copy link
Collaborator

bturner commented Jul 22, 2024

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?

@deepika433
Copy link
Author

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants