In Vaadin 7, I have two browser tabs open, looking at the same View, same search t ime. In both, I log when I click a button to Tomcat log. The second waits until the first finishes. Why?
[2024-01-29 13:56:55 EST] INFO com.mobiwms.website.view.eventtracking.EventTrackingView lambda$new$61446b05$1 Refreshing session/UI com.vaadin.server.VaadinSession@8c21b5/com.mobiwms.website.WmsUI@1bb1ff6, date Mon Jan 29 13:56:55 EST 2024 [2024-01-29 13:57:12 EST] INFO com.mobiwms.website.view.eventtracking.EventTrackingView lambda$new$61446b05$1 Finished refreshing session/UI com.vaadin.server.VaadinSession@8c21b5/com.mobiwms.website.WmsUI@1bb1ff6, date Mon Jan 29 13:57:12 EST 2024 [2024-01-29 13:57:12 EST] INFO com.mobiwms.website.view.eventtracking.EventTrackingView lambda$new$61446b05$1 Refreshing session/UI com.vaadin.server.VaadinSession@8c21b5/com.mobiwms.website.WmsUI@b2a3e6, date Mon Jan 29 13:57:12 EST 2024 [2024-01-29 13:57:22 EST] INFO com.mobiwms.website.view.eventtracking.EventTrackingView lambda$new$61446b05$1 Finished refreshing session/UI com.vaadin.server.VaadinSession@8c21b5/com.mobiwms.website.WmsUI@b2a3e6, date Mon Jan 29 13:57:22 EST 2024 I am still at the trouble shooting phase, trying to determine what is happening. Added some logging to find the problem.
I can open the same website in a totally different browser (say Firefox), and it will work. I believe it works because it is a totally new Vaadin session. My current working theory is that somehow things in the same Vaadin Session, but different UIs, are stepping on each other.
My first goal is to figure out why this happens. Once I know that, I can fix it so that two different tabs don't step on each other in this way.
Note that the "Refreshing" log statement is below:
eventTracking.addRefreshListener(e->{ Date now = new Date(); LOGGER.info( "Refreshing session/UI " + VaadinSession.getCurrent() + "/" + UI.getCurrent() + ", date " + now); dashboardForm.submit(); toggleParentVisibility(); now = new Date(); LOGGER.info( "Finished refreshing session/UI " + VaadinSession.getCurrent() + "/" + UI.getCurrent() + ", date " + now); }); And the definition of addReshestListener is, ultimately:
/** * Add listener to refresh button. If have listeners, shows refresh button. * @param listener * * @see com.vaadin.ui.Button#addClickListener(ClickListener) */ public void addRefreshListener(ClickListener listener) { if(listener instanceof ClickListener) refresh.addClickListener(listener); Collection<?> listeners = refresh.getListeners(ClickEvent.class); if(listeners instanceof Collection && !listeners.isEmpty()) refresh.setVisible(true); else refresh.setVisible(false); } The refresh is a normal button.
More info. I added some more logging and ran it in Eclipse. Here is the new code:
eventTracking.addRefreshListener(e->{ Date now = new Date(); Thread thread = Thread.currentThread(); LOGGER.info( "Refreshing session/UI " + VaadinSession.getCurrent() + "/" + UI.getCurrent() + ", date " + now + ". thread " + thread); try { java.lang.Thread.sleep( 30000 ); } catch (InterruptedException e1) { } dashboardForm.submit(); toggleParentVisibility(); now = new Date(); LOGGER.info( "Finished refreshing session/UI " + VaadinSession.getCurrent() + "/" + UI.getCurrent() + ", date " + now + ". thread " + thread); }); And here is a snippet of the logs:
Jan 29, 2024 4:14:55 PM com.mobiwms.website.view.eventtracking.EventTrackingView lambda$0 INFO: Refreshing session/UI com.vaadin.server.VaadinSession@28ec6dc1/com.mobiwms.website.WmsUI@67b6e45d, date Mon Jan 29 16:14:55 EST 2024. thread Thread[qtp1842482889-51,5,main] ... Jan 29, 2024 4:15:25 PM com.mobiwms.website.view.eventtracking.EventTrackingView lambda$0 INFO: Finished refreshing session/UI com.vaadin.server.VaadinSession@28ec6dc1/com.mobiwms.website.WmsUI@67b6e45d, date Mon Jan 29 16:15:25 EST 2024. thread Thread[qtp1842482889-51,5,main] Jan 29, 2024 4:15:25 PM com.mobiwms.website.view.eventtracking.EventTrackingView lambda$0 INFO: Refreshing session/UI com.vaadin.server.VaadinSession@28ec6dc1/com.mobiwms.website.WmsUI@554a269e, date Mon Jan 29 16:15:25 EST 2024. thread Thread[qtp1842482889-42,5,main] ... Jan 29, 2024 4:15:55 PM com.mobiwms.website.view.eventtracking.EventTrackingView lambda$0 INFO: Finished refreshing session/UI com.vaadin.server.VaadinSession@28ec6dc1/com.mobiwms.website.WmsUI@554a269e, date Mon Jan 29 16:15:55 EST 2024. thread Thread[qtp1842482889-42,5,main] As we can see, the second one definitely waits for the first one. Yes, I am clicking "Refresh" button in the second browser tab before the first one even finishes. I also notice they are the same thread id, qtp1842482889. I don't dig down to the thread level that often, but could it be that both browser tabs are on the same thread? Is there any way to prove or disprove that?
Note based on comments: Looks like my assumption above was close to correct: two UIs (one per browser tab) are stepping on each other.
My ultimate goal: Currently, if the user starts a process in one tab that happens to be a long process, they cannot do anything with our website in other tabs. That is what I am trying to fix, making it so they can do things in another browser tab with our website, without waiting for first task to finish.
java.util.Datewas years ago replaced byjava.time.Instant.