Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to optimize launch times of small Java command line programs? [duplicate]

Tags:

java

Possible Duplicate:
How to speed up Java VM (JVM) startup time?

Over the course of the day, I have to execute a series of small & quick Java command line programs. On Windows, to run a simple Java program from a the command line (like Hello World), sometimes it takes around 5 seconds due to the overhead of launching the java.exe process. The programs take a second to execute but the overhead of starting the programs is dominates the total execution time. Is there a way to optimize this?

Is there something like a Java shell that I can use to execute programs in-process? Similar to the Python shell?

like image 968
Sajee Avatar asked Nov 29 '11 14:11

Sajee


2 Answers

This may be overkill, but you could set up an application server like Tomcat or Glassfish and run your programs within the server. From what I understand, one of the original purposes of Java Servlets was to eliminate the startup dely associated with traditional CGI programs.

I don't know much about Java, so I don't know if there are simpler solutions available. But Tomcat et al are already available, so you wouldn't need to write your own server program.

Edit: someone else pointed out a similar question, How to speed up Java VM (JVM) startup time? One of the answers to that question mentions Nailgun, which looks like a near-perfect solution to your problem.

like image 85
Jonathan Avatar answered Nov 15 '22 16:11

Jonathan


You might write your own shell. You can write a single command line program that embeds all the functionality of those "utilities". You launch it, you keep it running and then you make your queries via some syntax you decide.

like image 34
gd1 Avatar answered Nov 15 '22 15:11

gd1