P
Peter Beck
Hi -
I have a question for someone who has experience with both ASP .Net and
JSP/Servlets, relating specifically to thread safetly.
In JSP, we say that instance vaiables of a servlet are not thread safe.
Several threads could be running the same servlet at the same time, because
a new thread of a servlet - as opposed to a new servlet itself - is created
by requests for the servlet. Since there is only one instance of the
servlet object, there is only one set of instance variables, and each thread
could set them to values that are in conflict with those in another thread.
However, you can write thread-safe servlets by avoiding instance variables,
or by judicious use of the synchronize(){ } construction.
It follows from this that instance variables in JSP pages are also not
thread safe, since the JSP is simply turned into a servlet. In theory, if
two people are running the same JSP page at the very close to the same time
the second person to access the page could re-set the value of an instance
variable to something that causes improper results for the first person, who
may be only part way through the execution of the page. I believe there is
a directive you can use to "sychronize" the whole page, although many
authorities seem to discourage this.
Can anyone tell me if there is a similar issue with ASP .Net pages,
specifically variables in the "code-behind" page? Is there something
analagous to a "servlet" that is created by ASP .Net, of which only one copy
exists that many users are executing in different threads? Is there the
possibility that users will "step on" each other's instance variables (as
there is only one instance of the object)?
Regards to all -
Peter Beck
I have a question for someone who has experience with both ASP .Net and
JSP/Servlets, relating specifically to thread safetly.
In JSP, we say that instance vaiables of a servlet are not thread safe.
Several threads could be running the same servlet at the same time, because
a new thread of a servlet - as opposed to a new servlet itself - is created
by requests for the servlet. Since there is only one instance of the
servlet object, there is only one set of instance variables, and each thread
could set them to values that are in conflict with those in another thread.
However, you can write thread-safe servlets by avoiding instance variables,
or by judicious use of the synchronize(){ } construction.
It follows from this that instance variables in JSP pages are also not
thread safe, since the JSP is simply turned into a servlet. In theory, if
two people are running the same JSP page at the very close to the same time
the second person to access the page could re-set the value of an instance
variable to something that causes improper results for the first person, who
may be only part way through the execution of the page. I believe there is
a directive you can use to "sychronize" the whole page, although many
authorities seem to discourage this.
Can anyone tell me if there is a similar issue with ASP .Net pages,
specifically variables in the "code-behind" page? Is there something
analagous to a "servlet" that is created by ASP .Net, of which only one copy
exists that many users are executing in different threads? Is there the
possibility that users will "step on" each other's instance variables (as
there is only one instance of the object)?
Regards to all -
Peter Beck