Repository navigation
Closed
Labels
Milestone
Description
I am trying to configure different corePoolSize for 2 Mailer instances, but so far without success. As i understand from documentation, all i need is to define different clusterKey for each Mailer. But it doesn`t work as I expect. I also use batch-module.
- new SmtpConnectionPoolClustered beeing created here just for 1st Mailer. For 2nd I am getting warning "Global SMTP Connection pool is already configured with pool defaults ...".
Lines 84 to 91 in 375bbd6
private void ensureClusterInitialized(@NotNull OperationalConfig operationalConfig) { if (smtpConnectionPool == null) { LOGGER.warn("Starting SMTP connection pool cluster: JVM won't shutdown until the pool is manually closed with mailer.shutdownConnectionPool() (for each mailer in the cluster)"); smtpConnectionPool = new SmtpConnectionPoolClustered(configureSmtpClusterConfig(operationalConfig)); } else if (compareClusterConfig(operationalConfig, smtpConnectionPool.getClusterConfig())) { LOGGER.warn("Global SMTP Connection pool is already configured with pool defaults from the first Mailer instance, ignoring relevant properties from {}", operationalConfig); } } - So there is just one instance of ResourceClusters created with clusterConfig (including corePoolSize) from 1st MailerBuilder cofig. Then it`s beeing reused for 2nd cluster as well.
https://github.com/bbottema/clustered-object-pool/blob/5857ced611c5be3489cd3cb763bfce8421aab9d9/src/main/java/org/bbottema/clusteredobjectpool/core/ResourceClusters.java#L55
My config:
@Bean(name = FIRST_SERVER_HOST)
public Mailer mailerFirst() {
return MailerBuilder
.withSMTPServer(FIRST_SERVER_HOST, FIRST_SERVER_PORT)
.async()
.withThreadPoolSize(20)
.withConnectionPoolCoreSize(1)
.withClusterKey(UUID.randomUUID())
.buildMailer();
}
@Bean(name = SECOND_SERVER_HOST)
public Mailer mailerSecond() {
return MailerBuilder
.withSMTPServer(SECOND_SERVER_HOST, SECOND_SERVER_PORT)
.async()
.withThreadPoolSize(20)
.withConnectionPoolCoreSize(0)
.withClusterKey(UUID.randomUUID())
.buildMailer();
}
Activity
bbottema commentedon Dec 12, 2024
Hello!
There are some properties that are considered globally applicable (as defaults) for all clusters and cannot be changed after the initial registration. These are:
The properties that can be provided differently per cluster are:
If this doesn't work for you, please let me know your use case. Also, it would help me to know which part of the documentation wasn't clear enough so I can improve it. Thanks!
elalbertinoprimo commentedon Dec 13, 2024
Hello! Thank you for reply.
In my case we work with 2 SMTP-servers, one of which has a problem with handling a large number of open connections. So I would like to set a different value "connection pool core size" for it (0).
Regarding documentation, "(core size, max size etc.) are set and fixed by the first Mailer instance in the cluster " made me think that i can configure it different way for different clusters.
https://www.simplejavamail.org/configuration.html#section-batch-and-clustering:~:text=Note%202%3A-,The%20Connection%20Pool%20defaults%20(core%20size%2C%20max%20size%20etc.)%20are%20set%20and%20fixed%20by%20the%20first%20Mailer%20instance%20in%20the%20cluster.,-Subsequent%20Mailer%20instances
bbottema commentedon Jul 6, 2026
Fixed by making batch-module pool defaults scoped to the cluster key. Different cluster keys can now keep different Java API connection-pool defaults; mailers sharing the same cluster key still keep the first Mailer config for that cluster.
The upstream pieces are tracked in bbottema/clustered-object-pool#6 and simple-java-mail/smtp-connection-pool#8. Property-only multi-cluster configuration remains tracked separately in #618.
fix(batch): scope pool defaults to cluster keys (#565)
bbottema commentedon Jul 8, 2026
Released in Simple Java Mail v9.0.0, which is now available from Maven Central:
https://repo1.maven.org/maven2/org/simplejavamail/simple-java-mail/9.0.0/
Release notes:
https://github.com/bbottema/simple-java-mail/releases/tag/9.0.0