Thread for processing long

Gentlemen, good evening. I intend to present a modal window with an animated gif while the application performs a long process.
Before I start I call:

new Thread (new viewMov ()). start ();

Now start the long process.

and the class is as follows:

viewMov class implements Runnable {

     / / HERE I CREATE A WINDOW WITH GIF

     @ Override
     public void run () {
         mainView.getUI (.) access (new Runnable () {
             @ Override
             public void run () {
             
                / / BUT THIS PART OF CODE IS NEVER EXECUTED

             }
         });
     }
 }

Could anyone help me implement this idea?
Thank you in advance.
a hug

Is the Thread really not running (you can check for example by adding System.out.println(“test”); in the run method) or are the results not displayed on the client?

When you execute a thread in a Vaadin app without using polling or push the thread runs on the server-side and the changes which are made to the ui only get send to the client when the next server request occurst (for example by pushing a button).

Got it, Marius … That’s exactly what happens! … A Window only appears when the long processing ends … Could you show me an example for this idea? … I really appreciate your help. a hug

If you don’t need Push functionality in your app anyways you should use Polling as it is easier to set up and meets your requirements.
Here
is an example on how to use the built-in polling mechanism with a long running thread.

Hi, Marius, Thanked by its intention.
Two things:
First, an isolated project, the example worked. That is, the label began with a text and ended with another. But I need the run method, to be continuously powered. But if I put it detroit a while (true) {}, the method stops working.
Second, if I try to use the example in my application, the run {} method is never executed …
Any idea?

thank you.

In one of my apps i’ve made a clock thread which updates a label every minute. It was kinda like this:[code]

UI.setPollingInterval(1000);
Thread thread = new Thread(){
@Override
public void run(){
while(true){
UI.access(…update the label);
Thread.sleep(60000);
}
}}
[/code]Disclaimer: This code wasn’t made with an IDE and is just there to represent the basics of how i did it.

If it’s a periodical process you might even be better of either A) using a Timer instead of a Thread or B) use
this
instead of the Polling which comes with a listener which gets executed periodically.

Well if you want to see if the run method even works you might want to switch to
Server Push
which holds a connection between server-client and automatically syncs UI changes without having to make a separate server request.

Gentlemen, I again … Sorry for my incompetence but still can not run script long term, in a separate thread. I would like to show a modal window while the process runs. In this window I put an animated gif and a label showing how many items are being processed. I ask, anyone knows a more complete example of push or poll Vaadin?
Thank you in advance.
a hug

Hi Carlos,

//
ProgressBar progressBar = new ProgressBar();

// preapare worker
Processor p = new Processor();
p.addProgressListener(new ProgressListener(){
// your Processor call this whenever an piece of work is done
// an alternative would be: access the current state of progess via p.getProgress() - then you have to add the
// Refresher addon an register an “RefreshListener”
// Dear Vaadin, it would be nice to have such an Listener in den Core Framework :wink:
void onProgress(long progress) {
UI.getCurrent().access( new Runnable() {
public void run() {
progressBar.setValue(progress);
}
}
});

// display progress - if request is finished then the client browser will show an dialog
UI.getCurrent().addWindow(new Window(null, progressbar));
UI.getCurrent().setPollInterval(1000);

// start worker
new Thread(new Runnable() { public void run() { p.start() } }).start();

// It would also possible to start the processor if the dialog opens
dialog.attach() {
new Thread(r).start();
}

Kind Regards Andreas

http://www.ahoehma.de


https://github.com/ahoehma/vaadin-examples/tree/master/vaadin-progressbardialog

Now … yes! Andreas, thank you. You made ​​it possible to implement my idea. Thanks a lot!
a hug