Question about constructors in Java

前端 未结 8 640
我寻月下人不归
我寻月下人不归 2021-01-20 14:52

I have few questions regarding Java constructors

  1. Can a constructor be private? If yes then in which condition?
  2. Is a constructor a method or not?
8条回答
  •  被撕碎了的回忆
    2021-01-20 15:27

    1. Yes, constructors can be private. This is done when you want tighter or alternate control over instance creation such as with factory methods or with a pattern such as a Singleton.
    2. It is a method but it is not called directly. It is a special type of method invoked on your behalf when you create a new object.
    3. Constructors don't return anything, they create new objects.
    4. The default is package private. So public to any class within the package but not visible to code outside of the package.

    Thoughts on Tomcat performance and scalability: This is a highly variable situation based on your server hardware and types of requests and of course the quality, efficiency and memory footprint of the code serving each request.

    Your lower bound on concurrent requests was 500. Consider that you probably want to create a thread for each request and given a 1MB stack per thread you're looking .5 GB just for thread stack space. And this is before heap memory and the performance overhead of allocating that many threads. I think that if need to handle that many requests at a time you might want to consider a more heavy duty server like JBoss.

提交回复
热议问题