Take the 2-minute tour ×

What is More Faster Using Functions or Using Static Methods in multiple threaded programme?Please explain why it is faster.?

share|improve this question
Given that "function" isn't really a term used in Java, you should clarify your question. Ideally, give an example showing both approaches. –  Jon Skeet Apr 29 '12 at 7:38
You should static vs non-static methods. –  Chandra Sekhar Apr 29 '12 at 7:39
I think he means method, not function. –  Radu Murzea Apr 29 '12 at 7:40
@ChandraSekhar you should verb ;) –  Ivaylo Strandjev Apr 29 '12 at 7:40

2 Answers 2

up vote 2 down vote accepted

You may have heard that "pure functions" are better for multithreading. A pure function can often be implemented as as static method in Java, but it could also be implemented as an instance method. The main point is that when multithreading it is always better if you don't have any global variables that can change. So if you have an immutable object, that's as good as having static method implementing a pure function.

share|improve this answer

Even if there is a sensible difference between the 2 approaches (which I seriously doubt), you should never design your programs based on this. Good design should (almost) never be sacrificed to achieve better performance. Because you don't gain a lot, but you lose a lot.

share|improve this answer
+1: Even if you find there is a small difference, you may be disappointed to discover that the difference changes as the JVM improves. This means that if you change your design significantly just to suit it and find that this is actually slower later it can be disappointing. Stick you what is simple and clear and don't worry about every nano-second unless you can say how much difference it will make to the business. –  Peter Lawrey Apr 29 '12 at 8:42
Totally agree. The decision static vs. instance should be made based on whether this method logically belongs - to the specific object instance or to all objects of specific class. Though there may be a small performance penalty (public non-final method is a virtual call), it normally can be ignored, plus JVMs are getting smarter and handle that more and more efficiently. If such a difference really matter for your application, maybe Java is a poor choice. –  Andrey Nudko Apr 29 '12 at 10:19

Your Answer


