What is the difference between getDefaultInstance() and getInstance() in Session class?

前端 未结 4 2042
情话喂你
情话喂你 2021-02-04 03:57

What is the difference between Session.getDefaultInstance(props, authenticator) and getInstance(props, authenticator)? In general, when will you choos

4条回答
  •  故里飘歌
    2021-02-04 04:49

    If you read the documentation, you will see that

    getDefaultInstance Get the default Session object. If a default has not yet been setup, a new Session object is created and installed as the default.

    Therefore, if one does not already exist, it call getInstance()

    getInstance Get a new Session object.

    So, a new session object is created, regardless of whether one already exists.

提交回复
热议问题