3

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?

3 Answers 3

1

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.

3
  • "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. Commented Dec 9, 2009 at 18:30
  • that should read "which keeps calling the main-method with new parameters" Commented Dec 9, 2009 at 18:30
  • Depending on the context, "making a wrapper class" can be quite a significant effort... Commented Dec 9, 2009 at 19:21
0

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?

0

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

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.