Fix https://github.com/spring-projects/spring-framework/issues/24286

Comment From: sbrannen

@jhoeller, what do you think about using SingletonSupplier for use cases like these?

Comment From: quaff

@sbrannen , please feedback since you adopt SingletonSupplier in https://github.com/spring-projects/spring-framework/commit/48052881222bddae82ddbf0a8a242e12a79db490

Comment From: jhoeller

This is well spotted in general, however, I'm rather defensive about core facilities there. At such a low level, I generally prefer to keep the code as straightforward as possible... for memory effectiveness, for inlining in HotSpot, etc. We apply similar reasoning for Java 8 Stream usage in our code: avoiding it in core places but selectively embracing it for readability higher up the stack.

So while we don't have strict rules in place here, I'd nevertheless avoid SingletonSupplier usage in spring-core itself. It's primarily meant for higher-level integration code such as our scheduling and cache integration; using it if for XStreamMarshaller seems appropriate from that perspective.