How much trouble can I get into with this.

I want to update the caption of a button every so often (about every minute). I do not care if it happens in timely manner, but I do care if the update locks the whole UI while it updates, which is what is happening. So I took the accessSynchronously method, copied into my UI class, and renameed it accessAsynchronously. I also commented out the session.lock() and session.unlock() lines (see below). It seems to work, but I have also seen stuff that suggest that updating the UI without locking it might not be a good idea.

So my question boils down to, how much trouble will I cause myself if I deploy this code, so that I can just update the caption on a button? I wll not be changing anyting else in the UI or getting any values off the screen.

Thank you

    private void accessAsynchronously(Runnable runnable)
            throws UIDetachedException {
        Map<Class<?>, CurrentInstance> old = null;

        VaadinSession session = getSession();

        if (session == null) {
            throw new UIDetachedException();
        }

        VaadinService.verifyNoOtherSessionLocked(session);

//        session.lock();
        try {
            if (getSession() == null) {
                // UI was detached after fetching the session but before we
                // acquired the lock.
                throw new UIDetachedException();
            }
            old = CurrentInstance.setCurrent(this);
            runnable.run();
        } finally {
//            session.unlock();
            if (old != null) {
                CurrentInstance.restoreInstances(old);
            }
        }
    }

I don’t have the skills to answer how much in trouble you will get, but still out of curiosity:

  1. Why do you bother doing an access method, if you are not synchronizing the access to the UI.
  2. Is the performance hit for locking the UI for single caption update really that much?

I am doing the access menthod, because from what I have found out from research and other post trying to get this to work, that if you are accessing the UI from a background thread that is the way to do it, I am also new to Vaadin and also Java so I am kinda in the dark here also.

What I have been lead to believe the hit should not be that much, but what I have seen is that sometimes it is noticable when I deploy it. It is not a regular occurance, but between where it locks the session and where it releases the lock, those steps can lock screen. My issue also could be with my setup, but I am not sure.

Ok.
Use UI.access instead of UI.accessSynchronously.
And make sure you don’t run the whole async operation inside the UI.access, but instead when the async operation finishes, you update the UI inside UI.access.

I was using UI.access and in attempting to figure out the problem, saw that it called UI.accessSynchonously, so I gave that a try also. I was also only calling it to update the UI, everything else was done out side the UI.access, the only thing in the UI.access was the update of the button caption.

When testing in the development tools, and running just the UI on the local server, I did not have a problem. But when I deployed it to the server that we used for testing and handling other parts of the system, that is when problems were being reported back. It was like the little bit that was being done to update the UI was causing problem.

The thing is I do not need up to the minute, update of the UI. Instead it would be fine if I could just push the change of the caption into a queue of changes to be applied to the UI, the next time the UI was updated. But I have not found anything like that.

Thank you