简体   繁体   English

使用Java和Javascript驱动事件?

[英]Event driven with Java and Javascript?

I am trying to perform some computations on a server. 我正在尝试在服务器上执行一些计算。 For this, the client initially inputs some data which I am capturing through Javascript. 为此,客户端最初输入一些我通过Javascript捕获的数据。 Now, I would perhaps make a XMLHttpRequest to a server to send this data. 现在,我也许会向服务器发送XMLHttpRequest来发送此数据。 Let's say the computation takes an hour and the client leaves the system or switches off the system. 假设计算需要一个小时,并且客户端离开系统或关闭系统。

In practice, I would use perhaps polling from the client side to determine if the result is available. 在实践中,我可能会使用客户端的轮询来确定结果是否可用。 But is there some way I could implement this in the form of a call back, for instance, the next time the client logs in, I would just contact the client side Javascript to pass the result... Any suggestions? 但是有什么方法可以通过回叫的形式实现,例如,下一次客户端登录时,我将只联系客户端Javascript以传递结果...有什么建议吗? I am thinking all this requires some kind of a webserver sitting on the client side but I was wondering if there's a better approach to do this. 我认为所有这一切都需要某种位于客户端的Web服务器,但我想知道是否有更好的方法可以做到这一点。

Your best bet is to just poll when the user gets to the web page. 最好的选择是在用户访问网页时进行轮询。

What I did in something similar was to gradually change my polling time, so I would start with several seconds, then gradually increase the interval. 我在类似操作中所做的是逐渐更改轮询时间,因此我将从几秒钟开始,然后逐渐增加间隔。 In your case, just poll after 15 minutes, then increase every 5 minutes when it fails, and if the user closes the browser then you can just start the polling again. 在您的情况下,仅在15分钟后进行轮询,然后在失败时每5分钟增加一次,如果用户关闭浏览器,则可以再次开始轮询。

If you want some callback, you could just send an email when it is finished, to let the user know. 如果需要回调,则可以在完成后发送一封电子邮件,以通知用户。

Also, while you are doing the processing, try to give some feedback as to how far you have gone, how much longer it may be, anything to show that progress is being made, that the browser isn't locked up. 另外,在进行处理时,请尝试提供一些反馈信息,说明您走了多远,走了多长时间,有任何迹象表明正在取得进展,浏览器未锁定。 If nothing else, show a time with how long the processing has been going on, to give the user some sense of progress. 如果没有其他要求,请显示处理进行了多长时间的时间,以使用户有所进步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM