Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static varialbles and performance

 
Santhosh Kumar
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
We have a requirement where in we need keep a class level attribute which holds some constant data and would be used in each method for logging purpose. Now the question is, should that attribute should be static or non-static? which is better from performance point of view?
Thanks,
Santhosh.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Performance forum.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
if they are not likely to change then u can go with,
"final static" which would let compiler optimize it more...
otherwise, static would be faster i believe as instance variables needs to be accessed from Heap going via the object reference...
any better explanations?
regards
maulin.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A class-level attribute should be static.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreeing with Thomas -- even if there were a performance difference, it shouldn't even enter the picture here. The question smacks of premature optimisation. Way premature.
- Peter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic