-
-
Notifications
You must be signed in to change notification settings - Fork 272
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
ThreadPoolExecutor terminated when sending an async mail #204
Comments
Hmm, it's been a while since I took a dive into Java's concurrent libraries. Won't executor.isTerminated()` return true if it is shut or shutting down? If not, then that's the problem I think; the connection pool should be re-initialized once shutdown has been called. Actually, making it
I found that when sending mails from |
Actually I said that non-deamon threads would not prevent the JVM to stop, but that is the other way around: deamon threads would not prevent the JVM to stop. public static void main(String[] args) {
ExecutorService executor = Executors.newFixedThreadPool(5, r -> {
Thread thread = new Thread(r);
thread.setDaemon(true);
return thread;
});
executor.execute(() -> System.out.println("Async !"));
} My point is: yes we can solve easily the issue by nulling the instance of the thread pool in |
And about your question:
It seems that if the thread pool is shutting down, then public static void main(String[] args) {
ExecutorService executor = Executors.newFixedThreadPool(5, r -> {
Thread thread = new Thread(r);
thread.setDaemon(true);
return thread;
});
executor.execute(() -> System.out.println("Async !"));
executor.shutdown();
System.out.println(executor.isTerminated());
} |
@amanteaux, thanks for testing and by all means give it a shot! |
Ok great, thank you! I will try to do that tomorrow! |
Just be sure to branche off from the master branch. Develop is currently waaay ahead and won't release soon. Let's aim for 5.1.6 (I just released a bugfix in 5.1.5 a minute ago) |
Ok, noted, thank you! |
…n. Threads are now named. Removed redundant warning suppressions
… report back in the Future / Promise that is returned from an async send / testConnection invocation
… Runnable a little bit at the same time
Released in 5.1.6. Solution for the 5.x.x releases is simply to check if the connection pool was shutdown instead of terminated. Also when a mail thread fails, the exception is now logged and not thrown furter up. |
Hello,
In production I had this error with simple-java-mail 4.4.5:
The call was:
mailer.sendMail(email, true);
By looking at these classes:
There is indeed a bug:
checkShutDownRunningProcesses
method, the pool is shutdown if there is no more mail to send,send
method, the pool is started if it is null or shutdown.But the thing is, calling the
shutdown
method on aThreadPoolExecutor
is not a synchronized operation, it just Initiates an orderly shutdown.My main question is actually: why shutting down the pool if there is no mail to send?
In the comment before the shutdown is is written shutdown the threadpool, or else the Mailer will keep any JVM alive forever. But actually by default, the thread factory in the
ThreadPoolExecutor
build non daemon threads, so it will not keep the JVM alive.The text was updated successfully, but these errors were encountered: