Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Caleb Smith   on Aug 13 In Java Category.

  
Question Answered By: Gerald Cruz   on Aug 13

Only one instance of the servlet  is created in
the JVM. However, each time you call the doGet or
doPost method on a servlet, a new thread of that method
is created.Therefore, the class  variable
inCount only is created once, but each time you call the
doGet/doPost (and any other person who calls it through a
browser) will increment the single instance of
intCount.You need to keep your doPost/doGet methods
threadsafe. Unless you want the above behavior (a counter for
people visiting the page or something like that), you
need to make all your variables method level
scope.What you want the servlet to do each time you call it,
should be contained in the doGet/doPost method anyway.
Access variables declared in those methods.

Share: 

 
 
Didn't find what you were looking for? Find more on What's servlet? Or get search suggestion and latest updates.


Tagged: