my dog learned polymorphism*
The moose likes Performance and the fly likes Static varialbles and performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Static varialbles and performance" Watch "Static varialbles and performance" New topic
Author

Static varialbles and performance

Santhosh Kumar
Ranch Hand

Joined: Nov 07, 2000
Posts: 242
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

Joined: Jan 30, 2002
Posts: 3451
Moving this to the Performance forum.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
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

Joined: May 05, 2000
Posts: 13974
A class-level attribute should be static.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static varialbles and performance
 
Similar Threads
arrays merge and sorting
RequestDispatcher Parameters
To be static or not to be static
HttpActivationListener question
better code for try and catch