Sure, starting a JVM for each request is an extremely bad idea. That's exactly where Java is slow.
It should be pretty easy using e.g., ServerSocket. Start a process and send requests to it. It's not the fastest solution, but simple and a guaranteed huge speedup.
A JAR file is sometimes an "executable", but it's always a "library". It's actually just a renamed ZIP file, so you can easily look what's inside (and I wouldn't call it reverse engineering). There's a file called manifest containing a reference to the main class. You can write your own class calling the original main
or ignoring it.
For this you don't need to modify the original JAR at all. Just make you own, but you don't even need a JAR file. For something as simple a single class should suffice. Then you call it like
java -cp "old.jar;." YourClass
assuming you're using Windows (otherwise replace ;
by :
), YourClass
is in the main package (which is usually a bad idea, but OK for a single class project), and YourClass.class
(i.e., the compiled version of your YourClass.java
is in the current working directory.
I wouldn't go for a faster and more complicated solution like using ServerSocketChannels, as it's not worth it. Starting a new JVM takes time, moreover, it starts with interpreting bytecode and compiling it... that far worse than some communication overhead. You could save some more microseconds....