• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

confused by singlethread interface

 
Forrest Xu
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
singlethread interface problem from Hanuman Deshmukh book at page 160,
it says that:
"The specification guarantees that if a servlet implements this interface, the container will not execute the service() method in more than one thread simultaneously."
I understand this is why it is OK for sample at page 161 based on above statement.
but I am not clear the following word from Hanuman Deshmukh book at page 160.
To avoid the performance problem, a servlet container may create multiple instance of the servlet class. In short, multiple requests will still be processed simultaneously but by different servlet instance.
I dont think the container whose singlethread interface implemented by this algrithm will make
the sample code at page 161 works fine. The reason seems simple, two instances(evevn they are different) can not wirte
any information in to the same files simultaneously .
Please help me,
Thanks,
 
chi Lin
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frank,
Please note there is a static variable instanceNumber declared in listing 10.3 to keep track different file name for each instance instanitated by container. (so no conflict here)..
In fact, if you reading down after listing 10.3 you will see the description about this static variable.
HTH
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic