5

Using Vaadin 14 I am facing the following error while I try to execute below code

          UI current = UI.getCurrent();
            Thread th = new Thread(() -> {
                UI.setCurrent(current);
                current.access(() -> {
                 //calling my service to save the data
                 current.push();
                });
             });
            th.start();

I get this above error very rare but need to remove that as it shows in UI.

lbonn
  • 2,499
  • 22
  • 32
kushal Baldev
  • 729
  • 1
  • 14
  • 37
  • 2
    would you please share what error you are facing? – Yogesh Feb 05 '20 at 11:00
  • Trying to start a new request while another is active in vaadin 14,P.S I get this error in like in pop up – kushal Baldev Feb 05 '20 at 11:02
  • This has to do with the fact that all background Threads like this are not scoped to a web request. Without such a web request, you can't invoke rest services I believe. If you had a repository that saved the data directly (without REST) this should work. I don't know too much about this so I will not write an answer. But using this information you should be able to dig deeper and find the problem yourself eventually. – kscherrer Feb 05 '20 at 16:26
  • to prevent the error message from showing, I think setting an UncaughtExceptionHandler to the Thread will help. `th.setUncaughtExceptionHandler((a,b) -> logger.error("...."));` you can now define yourself what happens when this occurs – kscherrer Feb 05 '20 at 16:28
  • According to [doc](https://vaadin.com/docs/v14/flow/advanced/tutorial-push-configuration.html), did you set a push mode? If "automatic" then you shouldn't push manually I guess. – Steffen Harbich Feb 06 '20 at 14:49

0 Answers0