Skip to content
Advertisement

Tag: autocloseable

How to close aws client in aws lambda

I am trying to correctly write an aws lambda using Java that will use aws sdk SqsClient and SnsClient. I see that these clients implement close() method, and it is generally a good practice to call this method when client is no longer required. And the best practices for lambda (https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html) advices to Initialize SDK clients and database connections outside

Is try-with-resource not safe when declaring multiple effectively final resources?

Since Java 9 we can use effectively final variables in try-with-resources. The example below presents a situation where one of the resources initialization throws an exception. When I run this example, the only output I get is a RuntimeException, meaning that Resource1 was not closed. That was expected, since it wasn’t initialized in the try-with-resources. But, is this the expected

What does idempotent method mean and what are the side effects in case of calling close method of java.lang.AutoCloseable?

Java docs of close() method of java.lang.AutoCloseable says Note that unlike the close() method of Closeable, this close() method is not required to be idempotent. In other words, calling this close method more than once may have some visible side effect, unlike Closeable#close() which is required to have no effect if called more than once. However, implementers of this interface

Advertisement