wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes is final class variable is thread safe? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "is final class variable is thread safe?" Watch "is final class variable is thread safe?" New topic

is final class variable is thread safe?

Jo Liang

Joined: Dec 10, 2001
Posts: 11
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
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
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.

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
It is sorta covered in the JavaRanch Style Guide.
subject: is final class variable is thread safe?
Similar Threads
Static variable
Thread Safe Objects
how final variable can be manupulated?
Marking a variable static final is thread safe
How to make a static variable thread safe?