Are static methods good for scalability?

后端 未结 8 512
故里飘歌
故里飘歌 2021-02-04 19:03

Does static methods and class are good for scalability ? I think so static class/method improves scalability of application and instance methods doesn\'t scales much. So is it g

相关标签:
8条回答
  • 2021-02-04 19:34

    It depends on WHY the method is static. If it's static because it truly does not need context, then it will probably scale very well compared to something of similar complexity that is not static because it requires context.

    However, if it is static merely because you cannot retain the needed context and must still pass it in, or because of some artificial goal of having more static methods, then I would suspect that it will actually scale LESS than the comparable method as non-static.

    In fact I think that ASP Classic proved this point.

    0 讨论(0)
  • 2021-02-04 19:35

    There are three problems to consider with static methods:

    1. You may introduce a bottleneck if your static method has a large critical region. The largest of course is to declare the whole method synchronized. If it can only be executing one at a time then it's a potential issue;
    2. Is whatever it's doing still consistent if you're running the same method in different VMs and on different machines? and
    3. Any method that relies on static methods has problems with unit testing.

    It's not generally considered best practice but static helper methods are common. Too complex and another approach should probably be considered.

    0 讨论(0)
提交回复
热议问题