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

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Hello, possibility to push in grid archetype-application-example ??

Rubén Espinoza
4 years ago Apr 23, 2017 3:41pm
Pontus Boström
4 years ago Apr 26, 2017 8:54am

Hi,

Push should work.There are few things that could be good to check:
- Do you have @Push annotation on the UI?
- Then you also need asyncSupported true for the VaadinServlet (is true by default)
- UI.getCurrent() should only be called from an UI thread. It would be better to pass the desired UI instance to class Hilo.
- You should not set polling interval when using push (it is redundant)
- getUI() is not thread safe and it might return null if the component is detached. It would be better to pass the correct UI instance to the thread before it is started. 

Hope this helps,
Pontus

 

Rubén Espinoza
4 years ago Apr 26, 2017 12:59pm
Martin Vyšný
4 years ago May 03, 2017 12:18pm

The problem is indeed in the Hilo class. The UI.getCurrent() returns null (since that thread is not an UI thread) and thus produces a NullPointerException. Yet, that exception is happily ignored and eaten by Java as the thread terminates, and it's *not even displayed in the console*. This is a horrible JVM decision, but one we have to live with. As a rule of thumb, I always write Thread.run methods as follows:

public void run() {
  try {
     ... do your stuff
  } catch (Throwable t) {
    logger.log(t);
    // or t.printStackTrace();
  }
}

So, instead of using UI.getCurrent() in the thread, pass the UI instance via a constructor parameter to the Hilo class; I assume you will construct the Hilo class in an UI thread which will then return non-null for UI.getCurrent().

Rubén Espinoza
4 years ago May 07, 2017 4:04am