0

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.

8
  • 2
    If both tabs share the same session, then this is to be expected. The UI state tree is stored in the session and very roughly speaking, when a request hits the server, per session there will be lock for this UI state until the request is done. Commented Jan 29, 2024 at 21:26
  • Rats, so my assumption was correct, sort of: the 2 UIs are sort of stepping on each other because in same session. Is there a way to maybe force a new session in the other tab? I am 99% sure, based on another post, that it is not possible, but thought I would ask. Commented Jan 29, 2024 at 21:39
  • By the way, java.util.Date was years ago replaced by java.time.Instant. Commented Jan 29, 2024 at 22:10
  • Why do you have a collection of listeners? Commented Jan 29, 2024 at 22:14
  • Date is still useful in many cases, and does not cause problems. I use whatever is best for the situation I am dealing with. The "collection" is only so I know we added a listening to the button. I use it, as per the code, mainly to hide or show the button. The code I am showing is a local library function. Vaadin 7 does not have a simple "does component have listeners", but it does let me get the collection. Made my life easier to let lower-level code control the visibility of the button. Commented Jan 29, 2024 at 23:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.