Calling an application from a web server asynchronously

♀尐吖头ヾ 提交于 2019-12-08 02:12:35

问题


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?


回答1:


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.




回答2:


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:


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



来源:https://stackoverflow.com/questions/9973339/calling-an-application-from-a-web-server-asynchronously

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!