How do I run a jar file in multiple threads?

I need to run an executable JAR file in multiple threads / cores. The JAR file does not implement Runnable. I was looking for a way to do this and couldn't find one. Is it possible to make a JAR file use multiple threads / cores without accessing the source code?

Currently. if I just run the JAR file fine, it only uses one core.


source to share

3 answers

It is not possible to create a magic program (no matter if it is packaged in a Java JAR file or in some other way), automatically use multiple cores. The program must be written to use multiple cores - there is no other way.



No, you cannot. You can run multiple processes java

running the same JAR in different threads, but that might not be what you want.



If jar is a jar executable, then it has a main method (the main class is specified in the jar file manifest). you can call this main method on your own Runnable instance.

however, if classes in this jar are using static resources without proper synchronization, this strategy will not work. if so, you can set up a separate ClassLoader for the Runnable and run each jar instance in its isolated ClassLoader (then you will need to call the main method using reflection).



All Articles