• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

thread safety: manning study kit error??

 
cyril vidal
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
manning exam study kit, P.161, gives an example of servlet implementing SingleThreadModel interface.
I believe the RequestInfoWriterServlet isn't thread safe although, because implementing this interface doesn't prevent problems with shared variables as static ones.
The code is the following (snippet):

The problem which may occur is the following:
Instance 1:


Instance 2 (processing requests concurrently):


Instance 1:

Instance 2:

So the two instances of RequestInfoWriterServlet write out to the same file...
Just my two cents...
Any suggestion or critical would be welcome,
Regards,
Cyril.
[ November 16, 2003: Message edited by: cyril vidal ]
[ November 16, 2003: Message edited by: cyril vidal ]
[ November 16, 2003: Message edited by: cyril vidal ]
 
Denny Permana
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Cyril,
I'm agree with you that static / class variable is never thread safe. In Appendix E p.495, Manning says that Class or Static variables is NEVER thread safe. I hope there has been an errata for this case.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic