Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

i have a PHP application that invokes a command line to execute some specific operations.

The command line calls a 'java -jar somefile.jar arg1 arg2'

The problem is that this is slow, since it has to startup the jar every time it get's invoked.

Is there any way keep the java machine code in cache or is there any way to optimize the whole process?

Thanks, joel

Update: The JAR was developed by our team.

To use as a service, i'll have to install some java server (tomcat or alike), right?

And how about a java php bridge? Can that be any faster?

share|improve this question

3 Answers 3

If you do it via command line, you're actually launching another executable program ("java"), so you can't have any control on it.

What you need is a service (in Windows) or a daemon (in Linux) which can receive requests and process them; without knowing the internals of what that Java application is doing, there's no solution we can provide.

Update

It strongly depends on what the application is doing.
It's perfectly possible to have a Java application running as a service and process requests, f.e. by listening for them on a network socket and returning its output through the same socket.
A Java application server (like Tomcat) is usually involved in dynamic web pages generation, not "pure" data processing.

Anyway, the Java application should be re-designed to work like that; you can't just take something that wants to be called for a single run via command line and use it as a back-end service without any modification.

share|improve this answer
    
"you can't just take something that wants to be called for a single run via command line and use it as a back-end service without any modification", that's not completely true. It's particularly easy in Java (as opposed to other languages where main is in the global namespace), you just make a wrapper class which calls the main-method with new parameters. –  falstro Dec 9 '09 at 18:30
    
that should read "which keeps calling the main-method with new parameters" –  falstro Dec 9 '09 at 18:30
    
Depending on the context, "making a wrapper class" can be quite a significant effort... –  Massimo Dec 9 '09 at 19:21

Well, there isn't any way to make the command line you've got go any quicker. That command will load the jvm, run the code, then unload everything. That's just what it does.

I'd probably try to set up a SOAP service or something. Or you could have the java app bind a socket, and connect with php that way.

How much control do you have over the java program? Are you stuck with it as-is?

share|improve this answer

You can use Nailgun to avoid the startup overhead of the JVM.

http://martiansoftware.com/nailgun/index.html

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.