Skip to content

Thread safety for lazy-cached domain services in MontonioClient #37

@rammrain

Description

@rammrain

Summary

MontonioClient.orders() uses lazy initialization without synchronization. Under concurrent access, multiple OrderService instances may be created (benign race — last write wins, no corruption). As more domain services are added, this pattern will repeat.

Context

Design decision from #16: opted for simplicity over thread safety since SDK clients are typically single-threaded. This issue tracks adding thread safety if it becomes a requirement.

Options

  • synchronized on orders() — simplest, minimal contention for a rarely-called method
  • volatile + double-checked locking — avoids synchronization on the hot path
  • Eager initialization in constructor — simplest but allocates unused services

Acceptance Criteria

  • MontonioClient.orders() is safe to call concurrently from multiple threads
  • No performance regression for single-threaded usage

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions