Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Running threads in background
Dear Vaadin(ers?)
I've been making a Vaadin web application these last few weeks and so far it's been great. However, I've run into a big hurdle that I can't seem to get over.
I am running an application on the server which needs to process a few tasks. In this case this process takes ~5 minutes. Now obviously I don't want my user to spend 5 minutes looking at a pop-up, so I want to place this process in a separate thread. This is what I have now:
class RunScenario implements Runnable {
Collection collection = stuff for collection;
EngineService engineService = new EngineService();
public void run() {
engineService.launcher.runScenario(collection.application.getName(),
collection.scenario.getName(), collection.environment.getName());
UI.getCurrent().access(new Runnable() {
@Override
public void run() {
Notification.show("Finished running application: " + collection.application.getName()
+ " scenario: " + collection.scenario.getName() + " on environment: "
+ collection.environment);
}
});
}
}
However, when I run "new RunScenario().run()" my browser is still showing the loading bar until the process is done. Then it finishes with the other tasks and closes the pop-up.
I dont see what I'm doing wrong, maybe I'm implementing this incorrectly? I could use some advice.
Many thanks in advance
Hi,
I don't see a new thread anywhere. Please try the following:
Thread thread = new Thread(new RunScenario());
thread.start();
-tepi
Hey Tepi
Thank you so much.... seems like I had some tunnel vision going on...
I kept running it with new RunScenario().run(); Now it seems to work properly.
Thank you again
Hi all,
my problem fits to the title "Running threads in background".
I want to have a background thread, which runs independent from any session. I only found the following approach, not independent from any session and not working very long. The timer process starts with the first session:
static { final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); scheduler.scheduleWithFixedDelay(presenceRequester, 0, 20, TimeUnit.SECONDS); }
This works over the day if there are sessions. Then at some time it stops (I think after the last session is destroyed) and it does not start again with a new session. I don't find any error messages in the logging.
Can anyone help? What are my mistakes? How to set up such a static background process?
Best Regards, Wolf Michna
Hi,
seems to me you could use some scheduling tool, e.g. Quartz is an easily configurable tool for this http://quartz-scheduler.org/. If the background process is independent from the UI, I would keep it separate from the UI code - that said, of course you can add/remove/start/stop these timers from the UI if needed.
-tepi
Hi Teppo,
thank you for your hints. The solution was to find and to eliminate all connections to the UI. The ScheduledExecutorService makes his job now. It only updates container extended from IndexedContainer. That works now.
Regards, Wolf