• Post Reply Bookmark Topic Watch Topic
  • New Topic

volatile variable in a Servlet  RSS feed

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Servlet which will respond to GET calls by returning the
current version. The current version is maintained in a volatile
member variable.


About 99% of the calls to this servlet will be GET calls asking
for the current value in m_revision. Clients will use the result
to decide whether they need to upgrade/downgrade.

From time to time, an administrator will modify the value.

After reading Goetz's Managing Volatility article, I'm quite confident that my code is
"safe" for my application's requirement. The article states that volatiles
are ok for variables whereby:

1. Writes to the variable do not depend on its current value.
2. The variable does not participate in invariants with other variables.

And my app conforms to both requirements.

Did I miss out anything that my jeopardise my application ?
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It also matters as to how you change the revision. Is that process atomic?
Generally, making non-primitive data as volatile does not help until and unless all the fields of the object are also volatile.
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well Revision is an immutable class. When the admin assigns a new version, I just do an assignment.
[ December 26, 2007: Message edited by: Pho Tek ]
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then that should be fine.
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool. And thanks.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anytime .... i liked the name of your servlet. BadAss ...
well now that its behaving nicely, you can rechristen it to GoodAss atleast
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!