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

前端 未结 4 2036
情话喂你
情话喂你 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:53

    For me, it was very important to use getInstance() instead of getDefaultInstance().

    Because after mail session properties was changed, mail session still was storing old properties.

    So getDefaultInstance() - it is looks like Singleton.

    As docs said:

    Note also that the Properties object is used only the first time this method is called, when a new Session object is created. Subsequent calls return the Session object that was created by the first call, and ignore the passed Properties object. Use the getInstance method to get a new Session object every time the method is called.

提交回复
热议问题