background/shared task on server?

As I understand it, each instance of my Vaadin application is tied to a session. So each user will see an independent view of the application and data. How can I create shared data so that each user sees the same, updating, data? Specifically, I would like to have a background task on the server updating the common data. Then each user can see the updated data.

One solution is to use a non-Vaadin processes to update a database. Then Vaadin just reads the DB for each client view application. But is there a simple way to share create a server-side task and share the results among the running applications?

Have you considered just putting the data in a static variable (or a singleton), for example in your application class?

For example:

public class GasDiaryApplication extends Application {
    // Data is shared between user sessions
    static Prevayler prevayler = null;
    static UserBase users = new UserBase();

    public void init() {
        // Initialize persistence if first instance
        if (prevayler == null) {
            try {
                prevayler = PrevaylerFactory.createPrevayler(users, "gasdiarydata");
            } catch (IOException e) {
            } catch (ClassNotFoundException e) {

Well, I’m not sure if this is the best example. You’ll have to consider thread-safety, for example.

Y, that’s what I was just trying. Works great. I’m coding in Scala, so it was literally as easy as changing “class” to “object” for my processing class to make it a singleton. I then made it extend Actor and respond to an update message. So now the concurrency is handled by the Actor messaging. Only one update is running at a time, and the update messages can be sent asynchronously. With a little additional logic, the actor won’t redo updates if they’re requested too soon. It just drops the queued up messages that arrive too quickly. The result is that each client requests fresh data frequently and is given the freshest data to use, while rate-limiting the updates.

Note that
you must synchronize on the application if you change user interface stuff outside the request/response cycle
. Otherwise strange things will occur if the user happens to interact with the application while the data is being updated.

Best Regards,