I’ve some problems with my English, so I apologize for mistakes.
I’m a beginner in Java programming. I use IntelliJIdea as IDE, Vaadin framework to create GUI and tomcat as a web server. Project was generated with maven.
To create an application I use the following sources as example:
There is Application class, (it’s not com.vaadin.Application inheritor), but singleton.
package com.exadel.dinnerorders.vaadinwindow.application;
import com.exadel.dinnerorders.entity.Order;
import com.exadel.dinnerorders.entity.User;
import com.exadel.dinnerorders.service.TasksManagerService;
import com.google.common.eventbus.EventBus;
public class Application {
private EventBus eventBus = new EventBus();
private static Application INSTANCE = new Application();
private User user;
private Order order;
private TasksManagerService tasksManagerService = new TasksManagerService();
private Application() {
tasksManagerService.start();
}
public synchronized static Application getInstance(){
return INSTANCE;
}
public EventBus getEventBus() {
return eventBus;
}
public void setUser(User user) {
this.user = user;
}
public User getUser() {
return user;
}
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
public TasksManagerService getTasksManagerService() {
return tasksManagerService;
}
}
And there is WebApplicationController class, which extends com.vaadin.Application.
package com.exadel.dinnerorders.vaadinwindow.application;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.*;
import java.util.Collection;
public class WebApplicationController extends com.vaadin.Application {
private EventBus eventBus = Application.getInstance().getEventBus();
private Layout loginLayout;
private String datePattern = "YYYY-MM-DD";
@Override
public void init() {
createLayouts();
createMainWindow();
eventBus.register(this);
setTheme("apptheme");
}
//some another methods for initialization main window and layouts
}
So, it seems my application works fine. But I faced the next problem:
I run application in idea on Tomcat 7 configuration. It launches without any problems. I open Opera as browser and log in as, for example, user1. Everything seems to work correct. Then I open Google Chrome or another browser and log in as user2. And if refresh window in Opera, it will show that know user2 logged in, but not user1. I had tried to do the same in different computers, and I got the same result. (on one machine log as user1, on another as user2).
Firebug shows that sessionsID are different in different browsers.
It seems that the problem are in web.xml file, where I configure servlets. But I had tried different configuration examples, and always got the same result.
Unfortunately, I didn’t manage to find answer in google or another forums.
I would say that your problem is related to the static Application singleton. Statics are shared among all the users inside a JVM.