The use of the SingleThreadModel interface guarantees that only one thread at a
time will execute in a given servlet instance’s service method. It is important to
note that this guarantee only applies to each servlet instance, since the container
may choose to pool such objects
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Anand Athinarayanan wrote:Well, our servlets can have instance variables and still be thread safe.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
While you can certainly define both member and class variables in a Servlet implementation class, there are J2EE constructs that do that and generally should be used instead
Jaikiran Pai wrote:I think Tim means using other "components" within the Servlets, as member variables. For example, Java EE allows you to inject EJBs within the member fields of your servlet:
Setting that field is the responsibility of the Java EE container and it knows when to set it.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Bear Bibeault wrote:
Anand Athinarayanan wrote:Well, our servlets can have instance variables and still be thread safe.
No they couldn't. In a hybrid approach, some instances may be shared across threads and you'd still have to write servlets to be thread safe. Unless you are talking about creating a new instance for each request.
I still see no advantages, as Tim asks.
In the 14 years I have been writing servlets, I've never missed instance variables. It's just a tiny amount of effort to make sure that servlets are written in a thread-safe manner.
shraddhasav
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |