The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes threads?/ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "threads?/" Watch "threads?/" New topic


srikanth reddy
Ranch Hand

Joined: Jul 28, 2005
Posts: 252

here the output is 012012....instead of 012345 ..
i know that if the variable is declared as volatile then every thread uses a copy of it and so the variable cant be declared both volatile and final it is not volatile then how come they uses their own copy..
but here ..if we wud have used static then there is only one variable and can expect 012345

Thanks & Regards<br /> <br />-Srikanth
Vlado Zajac
Ranch Hand

Joined: Aug 03, 2004
Posts: 245

2 different objects of Question47
2 different objects of A (Question47.a)
2 different variables i

If Question47.a was static, the output would be 012345.
Vlado Zajac
Ranch Hand

Joined: Aug 03, 2004
Posts: 245
Volatile does not mean that every thread has a copy (that does ThreadLocal).
Volatile means that threads cannot make temporary copies of the variable (which may otherwise be used for optimization).
I agree. Here's the link:
subject: threads?/
It's not a secret anymore!