Evil Washing Machine
Evil Washing Machine

Reputation: 1341

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. 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. He claims that the tomcat JVM will simply go to sleep after running the request and not complete the thread process. Therefore, he suggests that I use RMI to send the data to another process on the same server and process it there instead.

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?
  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?

Upvotes: 0

Views: 497

Answers (2)

Benjamin
Benjamin

Reputation: 1846

As far as i know, Vaadin does not use REST services for client-server communication. It is stateful and uses some kind of backing beans.

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

Upvotes: 2

André Schild
André Schild

Reputation: 4754

You can start separate threads from tomcat as needed. 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.

For vaadin 7 this has been greatly enhanced, to allow server push out of the box. In vaadin 6 you had to use some work arrounds for this.

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.

Upvotes: 1

Related Questions