Are static methods good for scalability?

后端 未结 8 536
故里飘歌
故里飘歌 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: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.

提交回复
热议问题