Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance: Let Mailer implement AutoCloseable, so it shuts down the connection pool automatically when disposed of by Spring #466

Closed
lburja opened this issue Jul 13, 2023 · 3 comments

Comments

@lburja
Copy link

lburja commented Jul 13, 2023

When using the connection pool (batch-module enabled), the documentation suggests that the application should call mailer.shutdownConnectionPool() to allow the JVM to shut down.

With Spring Boot (spring-module), beans that implement AutoClosable are normally automatically handled and their close() method is called by the Spring framework upon application shutdown (see Spring documentation).

Therefore, I would expect Mailer to implement AutoClosable, and shut down the connection pool in the close() method, so that shutdown can be automatically handled by Spring Boot (also try-with-resources)

@bbottema
Copy link
Owner

bbottema commented Jul 14, 2023

try-with resource would not be possible in combination with async emails; the connection pool might shut down before the email was sent. However, for closing applications from Spring perspective, this is an interesting thought.

@bbottema bbottema changed the title Let Mailer implement AutoCloseable, to shutdown the connection pool automatically when using Spring Maintenance: Let Mailer implement AutoCloseable, to shutdown the connection pool automatically when using Spring Jul 14, 2023
@bbottema bbottema changed the title Maintenance: Let Mailer implement AutoCloseable, to shutdown the connection pool automatically when using Spring Maintenance: Let Mailer implement AutoCloseable, so it shuts down the connection pool automatically when disposed of by Spring Jul 14, 2023
bbottema added a commit that referenced this issue Jul 14, 2023
…n when Spring wants to shut down the application. Note: this does NOT work with try..with resource in combination with async emails being sent. And using it with try..with resource when not async doesn't make sense, because why have a connection pool in that case.
@bbottema
Copy link
Owner

Without too much testing this, I've added and released this in 8.1.3. Give it a spin!

@bbottema bbottema added this to the 8.1.3 milestone Jul 14, 2023
@lburja
Copy link
Author

lburja commented Jul 14, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants