Hi,
when I began to use Push with Vaadin, I followed this tutorial: https://vaadin.com/book/-/page/advanced.push.html
In the complete example there is a new Thread spawned directly by the UI, but this is discouraged by J2EE standard and it also causes issues with Vaadin methods.
In fact, following this example I made a real worker thread that calls EJB methods (not Thread.sleep(3000) or Math.random() or any other useless stuff) for speeding up UI loading and I’m getting these problems:
- UI.getCurrent()
always
returns null
Neither HttpSession and VaadinSession are thread safe
, so they can be null when invoking methods on them inside threads
EJB marked with @RolesAllowed always throw security exceptions
, because threads are out of any context, so login informations (principal propagation and so on) are completely lost
EJB context
, where I’ve stored some useful information for my application,
is always empty
for the same reason described above
I’m getting exceptions everywhere using this approach, because any servlet is NOT thread safe, so I’m asking why an example of the official Vaadin guide suggests this solution?
Vaadin runs in a servlet, so anyone should be warned, not incouraged, about spawning threads inside it.
So , is there any other way to parallelize work without spawning threads inside the UI?
I’m very disappointed of using this approach.