Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Deploying Vaadin Application using Maven and Jetty

Jesus Martinez
1 decade ago Aug 31, 2010 7:30pm
Jean-François Lamy
1 decade ago Aug 31, 2010 8:32pm

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).

Jesus Martinez
1 decade ago Sep 03, 2010 9:29pm
Jean-François Lamy
1 decade ago Sep 04, 2010 1:36am

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.

Jesus Martinez
1 decade ago Sep 07, 2010 7:44pm