Skip to content

Instantly share code, notes, and snippets.

View alzimmermsft's full-sized avatar

Alan Zimmer alzimmermsft

  • Microsoft
  • Pittsburgh
  • 06:29 (UTC -04:00)
View GitHub Profile
@alzimmermsft
alzimmermsft / Lifecycle management.md
Last active December 18, 2024 22:06
Application lifecycle management for clientcore (and partially applicable to azure-core)

Short version

  • Any type which may have managed resources must implement Closeable and close any resources it manages.
    • For example, a service client might implement Closeable if it creates managed resources such as an ExecutorService. But, it shouldn't close Closeables passed to it such as an HttpClient.
  • HttpClient instances, since they are shared, must register with Cleaner and register a shutdown hook.
    • This will enable HttpClient to close if garbage collected or if the JVM is shutting down.
  • Response instance must register with Cleaner so they do not leak connections if they aren't consumed before garbage collection.
  • Allow for ExecutorService to be configured where asynchronous or parallelized execution is needed.
  • If not set, default to SharedExecutorService as this is a central configuration point for users.