Closed erichelgeson closed 5 years ago
I managed to temporarily circumvent this issue by adding the following to my application.groovy config
grails.mail.poolSize = 1
Seems the ThreadPoolExecutor
no longer allows a maximumPoolSize smaller than the corePoolSize for which the plugin sets the former to 1 and the latter defaults to 5 if left undefined.
if (corePoolSize < 0 || maximumPoolSize < corePoolSize)
throw new IllegalArgumentException();
@drennane Did you have any side effects for your solution? :))
@swEngineer4ever I have not tested it to any great extent as of yet, but it is legitimate config (as opposed to being a hack) and so I would suggest that the answer is application dependent.
The config merely stipulates that a single thread will be made available for sending email. I guess if your application is busy and email is a large part of its functionality (and is time sensitive), you may end up with large queues being processed by a single thread.
In my application, it's quite sporadic and so I do not see a problem developing for me from the outset.
@drennane Thanks for your quick reply. Is there a way to change the maximumPoolSize instead? Where this can be changed in the plugin?
@swEngineer4ever
Funnily enough, the plugin actually sets the max size to the same as configured core size. The problem arises out of the order this is done because setting the core size is done first which in the updated implementation in Java's underlying ThreadPoolExecutor
class, checks the max size (see the if statement above) and so bums out.
void setPoolSize(Integer poolSize){
mailExecutorService.setCorePoolSize(poolSize ?: DEFAULT_POOL_SIZE)
mailExecutorService.setMaximumPoolSize(poolSize ?: DEFAULT_POOL_SIZE)
}
The reason why setting to 1 works is because the initial constructor sets the max to 1 and so the assertion passes.
mailExecutorService = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
I don't see a separate facility to set the max size and I'm not sure if meta programming would work in this instance because the class is annotated with @CompileStatic
but someone can correct me if I'm wrong on that.
@drennane exactly this is what I noticed also -> the plugin sets the max size the same as core size, that's why I was wondering from where the 1 comes :/ thanks for the explanation.
I changed the order of setCorePoolSize and setMaximumPoolSize in setPoolSize and the error is gone.
Cool. Might be worth a pull request.
Hey, seems you have a fix, when are you releasing a new version of the plugin?
3.0.0 has been released.
Grails 4 M1 OpenJDK 11.0.2
Commit on a fresh 4.0.0.M1 project https://github.com/erichelgeson/grails4/commit/44bfdd583842680a918581a3514350572571b871
Hit /mail/index - get: