Dealing with Singletons which have to subclass

后端 未结 3 1169
攒了一身酷
攒了一身酷 2021-02-14 07:10

In the question What is an efficient way to implement a singleton pattern in Java? the answer with the most upvotes says, to use a Enum for implementing a singleton.

Tha

3条回答
  •  野的像风
    2021-02-14 07:44

    You shouldn't care about the actual instance(s) of your servlets - lifecycle management is handled by the servlet container according to the Servlet specification contract to which you have agreed. If it makes sense to implement parts of you server-side functionality as a singleton, then go ahead and do that any way you like and use it from your servlet.

提交回复
热议问题