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.
Update TextArea from thread
I have one panel class called ITKstartProfile where I added my TextArea on the Panel.
At the and of the Panel logic I start a Thread with a ITKInformationThread class
ITKInformationThread informationThread = new ITKInformationThread(editor) ;
informationThread.start();
public class ITKInformationThread extends Thread {
TextArea text = null;
long i = 0;
ITKInformationThread(TextArea t) {
text = t;
}
@SuppressWarnings("static-access")
public void run() {
while (true) {
text.setValue("thread" + i + "\n");
i++;
try {
this.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
When I do a System.err.print I see the variable I counting.
On my TextArea the values are not updated or added. I only see the first time thread0 but the thread1, thread2 etc are not displayed.
What do I wrong here?
Is it not possible to add information in a TextArea from a separate thread?
Chris
First: You need to synchronize on the Application-instance any time you update the UI from a background-thread.
Second: The server cannot trigger an update towards the client (as long you are not using special addons like IcePush). So probably the textarea is updated - but only on the server-side were no one ever sees it. To check this you can add for example a Button to your UI and click it after your thread ended. If the situation I just explained applies, you will suddenly see your changes afterwards ;). To get around this you will need to use IcePush, Refresher, a ProgressIndicator or my addon VaadinWorker.