Single Thread? ThreadLocal appropriate? Static ok?

Is a Vaadin application running on a single thread such that ThreadLocal can be safely used a persistent storage medium? Additionally, I suppose the normal rules of static fields apply to Vaadin and should not be used to share state for a single user since they will available to all users?

Hi,

The Vaadin application is not running on a single thread; there is one instance of Application per user, and that application is stored in (and retrieved from) the HTTP Session for each request.

It follows that you can use Application (or any object reachable from Application, e.g. windows, components, etc) to store state safely.

BTW : I’m a new Vaadin user too, so that is my take on it - if I’ve got it wrong, I’m sure other more seasoned users will be along shortly to point this out!

Cheers,

Charles.

Thanks. I was confused by this
WIKI article
. I realize that since they are storing just a reference to the application in a thread local, this is in reality just making the application available to all instances on a single request. Then you can use the application object to store/retrieve state.

Thanks again.

No. Your can store state in your application (fields) directly. Application state is stored in HttpSession and thus the state is transparently persisted through http requests. This in most cases ThreadLocals are not needed.

True. Statics are useful for sharing data between users and applications. They could be used for example for implementing caches and user-to-user communications. Still you have to remember that statics are only shared between users of one JVM - in multi-server configurations you can not rely them to be available to all users.