Calling an application from a web server asynchron

2019-05-23 08:33发布

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?

3条回答
可以哭但决不认输i
2楼-- · 2019-05-23 08:57

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.

查看更多
萌系小妹纸
3楼-- · 2019-05-23 08:58

You have two options.

  1. Start a separate JVM instance by doing a exec and using a java command.

  2. 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.

查看更多
萌系小妹纸
4楼-- · 2019-05-23 09:00

In your Java Application, create a thread and execute the code on it. The Java Application will return the call to the web server.

查看更多
登录 后发表回答