-
-
Notifications
You must be signed in to change notification settings - Fork 271
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
Implement more comprehensive ThreadPoolExecutor and expose config options #207
Comments
Thank you for following this subject @bbottema ! As you ask in the SO question, I am not sure allowing to configure the max number of threads in the pool is necessary:
I actually already encounter a similar use case when I had some issues with the default implementation of |
- Configuring ThreadPoolExecutor now with separate config options (thread pool core size, max size and keepAliveTime) - Added builder API for executor config options, including Javadoc - Added support for application.properties for these options, included properties in the web documentation
I pushed the changes which includes full configuration wiring, properties and builder API.
Why is a bounded queue needed here, @amanteaux? It is my understanding that number of threads can't exceed max threads. The fact they don't expire only means the threads are kept around for handling new tasks, not that you would get potentially unlimited threads resulting in an OutOfMemoryException. I also don't want to reject tasks that can't be picked up immediately because all threads are busy. |
Also, I'm thinking here that perhaps Simple Java Mail should offer API that accepts a custom BlockingQueue so advanced use cases are made possible such as maximising email processing without causes starvation, Out Of Memory, or rejected tasks (producers matching consumer throughput). Admitted this would only be useful for bulk users that generate a lot of new addresses or new emails. |
You are right, the number of threads can't exceed max threads. However, for the thread pool to start using new threads from |
Wow, did not know that! And also I don't understand it. If a queue refuses a task (because it's bounded), new threads will be made, even though the queue is already full? Won't it just reject the task again? Sigh, the more I read and discover about ThreadPoolExecutors, the less I understand about it it seems :/ Maybe we need a SimpleThreadPoolExecutor project to accompany SimpleJavaMail. I'm going to take a step back from this topic for for a few days. If you have some good ideas, by all means, use this branch, @amanteaux. |
Hehe I completely agree, the default thread pool executor behavior is counter intuitive. I think that tasks will start being rejected once the queue is full and at the same time max threads is reached. Though in SimpleJavaMail, I am not sure that providing more support than just configuring the max thread pool size + timeout makes a lot of sense. For very advance usages, it is possible to use synchronous sending and using a custom thread pool. I am leaving to you the measurement of the ratio: (benefits added by creating a custom thread pool + providing ways to configure it) / added complexity |
Makes sense. Perhaps just offering the option to provide a custom ThreadPoolExecutor covers all the cases leaving it to the users to decide if they need more advanced processing. |
…ExecutorService (ThreadPoolExecutor), with a default keepAliveTime of 1ms, allowing core threads to die idly as well
Hi @amanteaux, I finally got around to this topic again. I think I've finished the changes we had in mind:
I've set the default keepAliveTime to the smallest non-zero number, so that it kills off idle threads immediately keeping the JVM free to shut down without delay. I'm not sure what benefit there is to keep the threads alive for possible chained batches. Anyway new threads will spin up when needed. I figured this setup comes closest to the old behavior, except with less configuration and pool shutdowns/boots. Perhaps you can take a look? |
@amanteaux If you agree that this should behave pretty much the same as the old setup, I'll merge it to develop so I can continue on other stories. This is kinda in the way now :D I do feel this simplified configuration in the MailSender 👍 |
Hello @bbottema, sorry for the late answer! I will try to have a quick look at it this afternoon. It sounds good anyway. Thank you a lot for this! |
Hi @bbottema, it looks good! The thread pool options should cover 99% of the use cases, and the option to provide the custom thread pool will cover the 1% remaining use cases. I don't think we can expect more from Simple Java Mail. Thank you! |
Done. Will be in the 6.0.0 release! |
@amanteaux, released in 6.0.0-rc1!! Check out the new website... |
@bbottema Thank you!! It looks really good :) |
Great, let me know if you run into anything! |
6.0.0 has released as well, finally. |
This is the new path for the discussions fragmented over #204, #205 and #206. Paging Mr. @amanteaux.
Let's continue our threading discussion here? I really appreciate your input and you have already brought up some interesting points. And also, because of you I did some research and now know (again?) about some cool new things like BlockingQueue, SynchronousQueue and TransferQueue 👊
I backported the changes to "207-configurable-threadpoolexecutor" branched from develop, so we can implement this for 6.0.0.
The text was updated successfully, but these errors were encountered: