This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Servlets and the fly likes Static variables and performance.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Static variables and performance...." Watch "Static variables and performance...." New topic

Static variables and performance....

Daniel Silva

Joined: Nov 10, 2003
Posts: 9
There are some performance problem if I use static final variables and static methods into other class file and call this from a servlet ?
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
Not especially.
Sure, there might be a (very slight) performance issue when the other class is first loaded, but only if is loaded from a remote location over a network, but that is really rare.
Much more likely is that the other class you are using may have lots of dependencies on yet other classes, even though the static method you are calling does not make use of them. This can lead to "code bloat", where a lot of unused classes need to be deployed with your application just to satisfy the compiler. I know of several "utilitiy" jars that have this problem.
Calling methods from other classes is generally a good thing, unless the other classes have taken on too many responsibilitie sand become bloated.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 862
Both static and non-static method calls are VERY VERY VERY fast, and will make no practical difference. - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
I agree. Here's the link:
subject: Static variables and performance....
jQuery in Action, 3rd edition