在MainLayout中有以下广播处理程序
@Override
protected void onAttach(AttachEvent attachEvent) {
super.onAttach(attachEvent);
SecurityService securityService = serviceFacade.getSecurityService();
UI ui = attachEvent.getUI();
if (securityService.isAuthorized()) {
broadcasterRegistration = serviceFacade.getBroadcasterService().register(securityService.getCurrentUserUuid(), broadcasterMessage -> {
ui.access(() -> {
processBroadcasterMessage(broadcasterMessage);
});
});
}
}我不时地在日志中看到以下异常:
Exception in thread "pool-3-thread-5" com.vaadin.flow.component.UIDetachedException
at com.vaadin.flow.component.UI.handleAccessDetach(UI.java:415)
at com.vaadin.flow.component.UI.access(UI.java:515)
at com.vaadin.flow.component.UI.access(UI.java:502)
at com.example.ui.layout.MainLayout.lambda$onAttach$2(MainLayout.java:331)
at com.example.ui.service.broadcaster.BroadcasterServiceImpl.lambda$broadcast$0(BroadcasterServiceImpl.java:46)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)尽管存在此异常,但一切都正常工作,所以我的问题是--我是否应该对这个UIDetachedException异常做出某种反应?
发布于 2022-09-28 16:47:41
UIDetachedException是有目的的。当您试图访问关闭的UI时,会引发它。用户已关闭浏览器。您应该捕获异常,例如停止后台任务,取消广播侦听器的注册。
https://stackoverflow.com/questions/73883415
复制相似问题