• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

is final class variable is thread safe?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I know class variable is never thread safe but how about final class variable? Can we say it is thread safe since the value can't be changed?
Thank you.
- Jo
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the answer is definately Yes and No! It's true that a final variable for primitive types can not change however, a variable to an Object simply means the Reference can not change. Any state held by that obect can be changed (Unless the Object is immutable). So, the answer is "Thread Safety depends on your Implementation"
Note, even Instance Variables can cause Thread Safety problems if Objects are held in some sort of Singleton Implementation. You really need to pay attention to these issues when coding to ensure Thread Safety is maintained.
 
reply
    Bookmark Topic Watch Topic
  • New Topic