0

I'm working on a desktop app using Electron.js for the frontend and Java for the backend. Instead of setting up endpoints and using REST APIs for communication, I want to directly run my Java application using Node.js child_process.

I know Node.js is single-threaded, but I need my Java application to run with its full multi-threading capabilities within a Node.js child process.

Is it possible to run a multi-threaded Java application using Node.js child_process? How can I ensure my Java application retains its multi-threading capabilities when run from a Node.js child process?

2
  • 1
    May I ask why you think launching a Java process from Node.js would prevent using multiple threads in the former? What happens when you try it? Commented Jun 1, 2024 at 13:33
  • It seems you can run any process you want with child_process, and Java should not be the exception. The only disadvantage is that you will need to embed a Java Runtime Environment with your Electron application (or provide a Java Native application). But in principle, as long as you can run Java, the application should give you access to a multithreaded environment, as it will be running on the Java Virtual Machine (JVM). Commented Jun 1, 2024 at 16:34

2 Answers 2

2

A child process is a separate process spawned by the operating system that doesn't share any threading characteristics of its parent process. Even the language and runtime may be completely different, as with any process that you execute in your operating system.

Sign up to request clarification or add additional context in comments.

Comments

0

let’s say this:

NodeJS pid = 1000 parent_pid = 0

Currently, only the NodeJS application is in RAM.

When you create a child_process in your NodeJS code:

JAVA_APP pid = 1001 parent_pid = 1000

Now both the NodeJS and Java applications are in RAM.

If you kill the NodeJS app -> it will also kill the Java app. But the reverse is not true. The point of running as a child process is actually this. Additionally, there are some changes related to security for accessing the resources of that process, but that’s not our topic.

At this point, if your operation is multi-threaded, the operating system will manage how many cores your Java application will run on. So, if you’ve written your Java application to be multi-threaded, the operating system will handle it accordingly. Running it as a child process won’t affect this aspect.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.