简体   繁体   English

Vaadin + Tomcat Webapp可以用于连续运行线程吗?

[英]Can a Vaadin+Tomcat webapp be used to run a thread continuously?

I am trying to build a webapp with a Vaadin frontend which lets a user upload and process data on our server. 我正在尝试使用Vaadin前端构建一个Webapp,使用户可以在我们的服务器上上传和处理数据。 The process is quite complicated and is a multi-threaded app (let's call this the 'core'). 该过程非常复杂,并且是一个多线程应用程序(我们称其为“核心”)。 Whilst designing this app, I thought I could stick everything onto the tomcat server but a colleague of mine told me that natively, Vaadin is RESTful and will thus not run the business process continuously because the application is stateless. 在设计此应用程序时,我以为我可以将所有内容粘贴到tomcat服务器上,但是我的一位同事告诉我,Vaadin本质上是RESTful的,因此不会连续运行业务流程,因为该应用程序是无状态的。 He claims that the tomcat JVM will simply go to sleep after running the request and not complete the thread process. 他声称,tomcat JVM将在运行请求后直接进入睡眠状态,并且不会完成线程处理。 Therefore, he suggests that I use RMI to send the data to another process on the same server and process it there instead. 因此,他建议我使用RMI将数据发送到同一服务器上的另一个进程,然后在该服务器上进行处理。

I have a few questions about this: 我对此有一些疑问:

  1. Is all that he's claimed true? 他声称的一切都是真的吗? There are some intricacies of implementing Vaadin on Tomcat that I'm not aware of? 我不知道在Tomcat上实现Vaadin的一些复杂之处吗?
  2. More likely I think I'm misunderstanding him and he's actually explaining on why it's better to seperate presentation and business components (which I completely agree with). 我认为我很可能误解了他,他实际上是在解释为什么最好将演示文稿和业务组件分开(我完全同意)。 But on a purely theoretical point of view, would it be possible to stick the multi-threaded core onto the same tomcat server instance as the one running Vaadin? 但是从纯粹的理论角度来看,是否有可能将多线程内核与运行Vaadin的同一个tomcat服务器实例绑定在一起?

As far as i know, Vaadin does not use REST services for client-server communication. 据我所知,Vaadin不使用REST服务进行客户端-服务器通信。 It is stateful and uses some kind of backing beans. 它是有状态的,并使用某种支持bean。

Regarding your thread issue, if you call your long running task directly from a Vaadin component, it will block the thread processing your request until the task is done. 关于线程问题,如果直接从Vaadin组件调用长时间运行的任务,它将阻塞线程处理您的请求,直到任务完成为止。 From the browser point of view, you'll have to wait and see the spinning indicator until the process is done (or an exception due to request timeout is thrown). 从浏览器的角度来看,您必须等待并查看旋转指示器,直到该过程完成(或由于请求超时引发的异常)。

What you can do is to run your long running task in a separate thread. 您可以做的是在一个单独的线程中运行长时间运行的任务。 If you want the new thread to run on the same JVM, you do not need something like RMI. 如果希望新线程在同一JVM上运行,则不需要RMI之类的东西。 You can do it by either: 您可以通过以下两种方式之一进行操作:

Note that you'll probably have to implement some kind of notification mechanism to know when the thread has completed the task. 请注意,您可能必须实现某种通知机制才能知道线程何时完成任务。

You can start separate threads from tomcat as needed. 您可以根据需要从tomcat启动单独的线程。 It does not matter what frontend you have for this. 您拥有什么前端都没有关系。

But what's important is to access the vaadin UI components the correct way when you wish to update them from another thread. 但是重要的是,当您希望从另一个线程更新它们时,以正确的方式访问vaadin UI组件。

For vaadin 7 this has been greatly enhanced, to allow server push out of the box. 对于vaadin 7,此功能已得到大大增强,以允许服务器立即使用。 In vaadin 6 you had to use some work arrounds for this. 在vaadin 6中,您必须为此使用一些工作环境。

https://vaadin.com/book/-/page/advanced.push.html#advanced.push.running https://vaadin.com/book/-/page/advanced.push.html#advanced.push.running

We use this concept a lot for export and report generation. 我们在导出和报告生成中经常使用此概念。 - Use click on Export/Report - On the server we start a (low priority) thread which builds the report/export - During this, we update a progressbar on the client via server push - Once the thread has generated the export/report we send it to the webbrowser -使用“导出/报告”上的单击-在服务器上,我们启动一个(低优先级)线程来构建报告/导出-在此期间,我们通过服务器推送更新客户端上的进度条-一旦线程生成了导出/报告,发送到网络浏览器

If you wish to have a core running always and accepting "jobs" then perhaps you are better served with a job sheduler like quartz or similar. 如果您希望核心始终运行并接受“工作”,那么也许最好选择像石英之类的工作设备。

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

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