Are static methods good for scalability?

Are static methods and class good for scalability? I think a static class / method improves the scalability of application methods and instances that are not scalable. So is it good programming practice to write a static method when possible?

+4
java performance static-methods scalability
source share
8 answers

It depends on why the method is static. If it is static because it really doesn’t need context, then it will probably scale very well compared to something similar complex, which is not static because it requires context.

However, if it is static only because you cannot maintain the necessary context and still have to transfer it or because of some artificial purpose to have more static methods, then I would suggest that it will actually scale LESS than comparable method as non-static.

In fact, I think ASP Classic has proven this point.

+3
source share

Are static methods and class good? for scalability?

One has little to do with the other.

I think a static class / method improves application scalability and instance methods don't scale much.

Wrong. Why do you think so?

So is it good programming practice to write a static method when possible?

Not. In fact, this is a very bad practice, as it waives the benefits of object-oriented programming support.

+11
source share

There are three problems with static methods:

  • You can introduce a bottleneck if your static method has a large critical area. The biggest one is to declare the whole method synchronized. If it can be executed only once, then this is a potential problem;
  • Whatever he does is still consistent if you use the same method in different virtual machines and on different machines? and
  • Any method that relies on static methods has problems with unit testing.

This is usually not considered best practice, but static helper methods are common. Probably, a too complicated and different approach should be considered.

+3
source share

No static methods scale better. The infact style of programming (imperative or object-oriented) does not really matter for scaling. There are two main aspects of scaling, and what to do to improve the scale depends on what we mean:

1 Scaling by the number of requests processed a second time

This type of scaling is usually associated with adding more computers to the cluster to increase overall system throughput. The increase in scale is often associated with the initial reduction in the number of shared resources used when using caches, and then the subsequent division of access to data into fragments.

2 Data scaling

This is when the system receives more and more data over time, and operations that access the data (search, filtering, etc.) become slower because the algorithms are more complex than O (1). In this case, the usual strategy is to increase the number of read and write points and use parallel algorithms such as Map / Reduce.

But none of these aspects have anything to do with whether you use static methods or not, whether just a few queries work with large datasets or with single data sources.

+3
source share

Not. I think you can assume that each instance has its own copy of the method definition, taking up this amount of space for each instance, which is not the case.

Editing to add:

In case you are wondering how an instance method can actually be shared between instances: this is because each invocation of the implicity method of the instance method passes a reference to the instance object to the method. This is commonly called "implicit." In other words, when you define or call an instance method with two parameters, such as myMethod (a, b), you can think of it as actually being myMethod (this, a, b), and Java will take care This parameter is for you, without the need to explicitly define or pass it.

(This, by the way, is handled differently in Python, where you must explicitly put an object reference as the first parameter of the instance method definition, although not in the call.)

For an explanation of what happens at the Java bytecode level, here is the link: http://www.artima.com/underthehood/invocationP.html (See the article around: “The ref object is an implicit pointer that is passed to any instance method ".)

+2
source share

I think you are barking the wrong tree:

In the real world, scalability (or lack thereof) usually arises due to the relevance of one algorithm and the efficiency of operations performed with data warehouses (I think: good SQL queries).

Things like a static method or not (or% static methods) have nothing to do with system scalability at all. You probably have a super-scalable system that doesn't use static methods or a super-scalable system that uses them exclusively.

+1
source share

What form of scalability do you mean? Scalability, what code is supported and expanded in large and small projects? Then using only static methods is painful. Do you mean performance? If instance methods are slower (which I don’t believe in this commonality), this does not mean that they do not scale. If they need twice as many static methods, they also need twice as much time if you call them all 10,000 times. Choosing the right algorithms and presenting data decides much more about performance scalability.

Finally, if you think that static methods are the way to go, you should not use an object-oriented language such as Java. Try C or Pascal or classic base dialects.

0
source share

Voice down. The OP clearly does not quite understand the TOE. The instance method does not take up extra space when creating an instance object. Static methods are not going to save you anything unless you also avoid creating any instances, in which case you are going so far from what was created for the OO language, for which this was a pointless discussion.

0
source share

All Articles