This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

confused by singlethread interface  RSS feed

 
Forrest Xu
Ranch Hand
Posts: 94
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!