Search code examples
oracle-cloud-infrastructureoci-java-sdk

Should com.oracle.bmc.monitoring.MonitoringClient be closed every time after querying for metrics?


In the examples provided on using the Monitoring Client: https://github.com/oracle/oci-java-sdk/blob/master/bmc-examples/src/main/java/MonitoringMetricListExample.java https://github.com/oracle/oci-java-sdk/blob/master/bmc-examples/src/main/java/MonitoringMetricSummarizeExample.java, for the monitoringClient.summarizeMetricsData(request) a new Monitoring Client is created and closed after a request. Is it necessary? Or can this client be reused for the new request, so for example there will be one client for the whole runtime of the application?


Solution

  • closing the client after every request is not necessary. You can re-use the same client for multiple requests, e.g. for the whole lifetime of the application.