How inefficient is it to execute a jar inside a loop? What are the alternatives?

Viewed 114

I am currently working on a project that requires me to use both JAVA and C++. The JAVA part is responsible for printing to stdout a string that depends on the arguments passed to the main method with a method call (say getString()). But first, it needs to create multiple objects.

Currently, my C++ program creates a console and repeatedly executes the compiled JAVA program within an infinite loop to refresh the printed output on the console.

While this is a relatively small program, its efficiency and memory usage worries me as the C++ program continuously executes the jar file that consequently creates and destroys new objects each time.

I think that ideally, the C++ program should execute the JAVA program once and only call getString() at each iteration to limit all the objects instantiation to only once instead of every iteration.

That being said, I was wondering if that would make a difference and if so, is it doable? How?

0 Answers
Related