I have a web application made with Spring that runs on Tomcat. On the same machine there is a normal Java application.
I would like to execute the Java application by calling it from the web server, but i want to make it so the application won't use the server's resources (it involves the training of a classifier so it may take up a lot of resources and time) and it must not hang the server (so it must be called asynchronously).
Is there any way to do that?
Yes, from the web server register RMI callback with the standalone java application.
When the web application requests the standalone APP it would be synchronous call and would not take long time. Once when the standalone app is ready with the results it would invoke the web app using the RMI callback.
You have two options.
Start a separate JVM instance by doing a
exec
and using ajava
command.Spawn a new thread - this will use server's resources though.
You can also combine options 1 and 2 and create a thread that does the
exec
call.In your Java Application, create a thread and execute the code on it. The Java Application will return the call to the web server.