Wednesday, 28 August 2013

Singleton objects in Servlets

Singleton objects in Servlets

pI am unfamiliar with how the Tomcat6/Spring Server/Servlet performs
operations. /p pI recently ran into situation where I wanted the
servlet(s) to have a singleton class that would persist information
generated in the servlet class./p pFor instance, in one request a user
would specify some data, and the servlet would store the data into a
Singleton class./p pIn the next request, the user would send information
to the server that would modify the singleton class./p pHowever, in the
next request, it never seems like the data is persisted. Is it a bug in my
program, or is the lifetime of the singleton class different in the
webserver?/p pPS, I know that using a Singleton class to perform this
operation is stupid, but I am just trying to explain the problem./p

No comments:

Post a Comment