Vaadin Application can only be viewed by one user

Hello everyone,

I have the following very strange problem:

If I open my vaadin application in two browsers, the application is loaded two times in the first browser and the second browser displays just a grey area.

The problem also occurs if someone else trys to open the application on a different computer (in a different network).

Does anybody know what the problem is?

As you can imagine my application is pretty worthless like that.

Regards

Kevin

Guess 1: Are you storing something into static variables? They are shared between all users so you should not store application related info in such.

Guess 2: You are using some dependency injection framework that handles the application reference (should be one per active user) in an incorrect way?

It sounds like you populate the first initialized application instance instead of populating the one that has been created for the second user.

Hey,

Thanks for your answer!

Guess 1: I’m not using static variables, but static classes (And singleton design pattern). But those should be instantiated per user, right?

Guess 2: Nope, no framework at all. (Just hibernate for database access)

I really have no idea what the problem could be…the user isn’t even logged in or anything like that.

Regards

Kevin

The normal singleton pattern is not by session nor by user, but shared by the whole virtual machine.

If you want to have something only for the user, put it in your application instance or elsewhere in the session (note that all Vaadin components in an application etc. are a part of the session). Alternatively, you could use the ThreadLocal pattern, but it looks like
the wiki page
about it and Vaadin is a little outdated (there is a note at the beginning).

Oook…

Thank you very much for your help…i guess i need to re-design my application now =)

But this means, that i even cant use static classes to save information? I need to save things in the “MyVaadinApplication” class?

Sure you can, you just can’t have static classes which have user specific state. So if your class only contains something like this…

public static void save(Object o) {
   new DbAdapter().save(o);
}

… you should be good.

If you need static classes which are user specific, then you should take a look at the
ThreadLocal pattern
.

Hi,

As Henri noted before the wiki article is outdated. Is there anywhere an updated
ThreadLocal pattern
example? Or could you make a guess when the wiki article will be updated?

Thanks,
Thorsten

Oh, sorry, didn’t notice that he had linked to it as well. I’ve written a blog post about using ThreadLocals with Vaadin, you can read it
here
.

Hi,

nice article. But in your examples you still implement
TransactionListener
. The wiki on the other hand tells me to implement
HttpServletRequestListener
instead:

Which way is the best?

Thanks, Thorsten

Hi, sorry for the late reply, didn’t notice until now that this post got a reply. This exact same question has been asked in the blog post’s comments - take a look at them, I’ve shared my opinion there.