[concurrency-interest] Clarification: volatile, final and atomic ops

Jason T. Greene jason.greene at redhat.com
Thu Jan 15 18:41:41 EST 2009


Ashwin Jayaprakash wrote:
> Thanks Jason!
> 
> I knew about JSR-133, but it still does not clarify if accessing a 
> "final" field or local variable is slower than a non-final field, for 
> what ever reasons... Does a final field/variable access incur additional 
> cost?

A final field has cost since it does prevent certain reorderings that 
allow it to be safely published to another thread. Although, due to it's 
restrictions, final field access can be optimized more than volatile access.

-- 
Jason T. Greene
JBoss, a division of Red Hat


More information about the Concurrency-interest mailing list