I cannot open up 20-30 cmd window and run them separately, its heavy load onto processor
You have the overhead of (20-30)-1 JVMs with that method. You can create a second main class like this:
public static void main(final String[] args) {
int numberOfSimultaneousExecutions = 25;
java.util.concurrent.Executor executor = java.util.concurrent.Executors.newFixedThreadPool(numberOfSimultaneousExecutions);
for (int i = 0; i < numberOfSimultaneousExecutions; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
RealMainClass.main(args);
}
});
}
}
Now the JAR is running simultaneously in one JVM.
However, this is dangerous. If your code is accessing (and modifying) any shared static values your application will almost certainly break.
You can also take the number of simultaneous executions from the arguments:
public static void main(final String[] argsWithNum) {
int numberOfSimultaneousExecutions = Integer.parseInt(argsWithNum[0]);
final String[] args = new String[argsWithNum.length - 1];
System.arraycopy(argsWithNum, 1, args, 0, args.length);
java.util.concurrent.Executor executor = java.util.concurrent.Executors.newFixedThreadPool(numberOfSimultaneousExecutions);
...