2

I've gone through as much of the source code as I can bear for UriComponents and it appears to be thread-safe but was hoping that someone else can confirm this.

Essentially, I am creating a single instance of UriComponents using UriComponentsBuilder. This instance is shared and used to expand and create various URI's with runtime query/path params. Is this safe?

user1491636
  • 2,355
  • 11
  • 44
  • 71

1 Answers1

2

UriComponents and its sublass (HierarchicalUriComponents) are immutable. Any operation that returns a UriComponents creates a new instance. The state in UriComponents is marked final. So its safe to use it with multiple threads as they wont be able to modify the state.

ekem chitsiga
  • 5,523
  • 2
  • 17
  • 18