Deploying Vaadin Application using Maven and Jetty

Hello Vaadin Community,

I am currently working in a web application using Vaadin and a combination of Maven + jetty to deploy it.

Once I have deployed the application to the server, I connect to it from different browsers and have noticed that when I start playing around with the interface in one browser the changes are reflected in the other browser.

Here is an example.
Firefox, Opera, Chrome are all connected to the server hosting the application. I start playing around with my application using the Firefox browser and open up a pop up window. The pop up window is shown as expected in my firefox, but it is also shown in the chrome and opera browser even though I wasn’t even playing with those browsers.

It looks like there is only one instance of my web application, and every web browser that connects to the server hosting it gets the same instance.

I have my jetty code specify in the pom.xml of my project, and deploy it using maven, aka “mvn jetty:run”.
This is how it looks in my pom file.

						Redeploy every x seconds if changes are detected, 0 for no
						automatic redeployment
					<!-- make sure Jetty also finds the widgetset -->
						<baseResource implementation="org.mortbay.resource.ResourceCollection">
								Workaround for Maven/Jetty issue

Am I missing something in my specification of the plugin? Is this a normal behavior of Jetty ?

It is worth mentioning that I use the singleton pattern quite often in the architecture of the application. From what I understand, each request to connect to the server should make a new instance for each object, and not re-use existing singleton instances that other users are using. Is there a limitation when deploying an application that make use of the singleton pattern?

I appreciate your input on the matter.


The singleton is shared accross all sessions of your Web Application, because it was most likely created as a static and loaded by the class loader dedicated to your Web Application

That is one cause of unwanted sharing, but not the only one: servlet containers instantiate each servlet once, and call the service() method once per HTTP request. So if you have

  1. a regular variable in a servlet class, or
  2. any type of static variable (including a typical singleton), or
  3. anything in the application context, or
  4. anything in the JNDI context,

ALL of those are shared.

A singleton should only be used for something that MUST be shared across all browsers and sessions. You want exactly the opposite. Anything private to each browser should be a private variable inside the Vaadin Application (which is the HTTP Session).

Thanks for the response.

You are right, my singleton variables are indeed static.

I will have to look for another way to approach this issue.

Do you think that this behavior will change if I were to use Tomcat? I am not too familiar with Tomcat, but from what I have read from their website and tutorials, it seems that JBoss could create a servlet for each request to connect to the application and maybe the problem with singleton will be solved.

Tomcat will be the same as Jetty.

If for whatever reason a container handles servlets differently, creating new instances, I would strongly advise against relying on the behaviour. The behaviour I described is pretty much universal AFAIK.

I see.
Thanks for the input on this.

Time to start removing static objects from my project.