• Post Reply Bookmark Topic Watch Topic
  • New Topic

member variable in servlet  RSS feed

 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I declared a private boolean member variable in my servlet called "errorFlag". I was setting this to true when an error occurred. I noticed that if an error occurred and set the flag to true, that flag would be initially set to true for other requests, similar to a static member variable. Should I not use member variables in servlets? Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66154
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should I not use member variables in servlets?


Engrave the above in granite and hang it over your computer!

Seriously, by declaring a read/write member variable you have renderred your servlet non-thread-safe. Don't do it. That's why there are the various scopes for storing scoped variables in a controlled fashion.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!