-
Notifications
You must be signed in to change notification settings - Fork 419
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
posting to a shutdown thread pool? #192
Comments
Looks to me like Java thread pools do what I'm suggesting -- they use the overflow policy for work submitted to a shut down pool too. See "Rejected tasks" at: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html
|
Nice catch. Thank you. The overflow policies are a recent addition. The current post-shutdown behavior was written first. The behavior you suggest makes more sense now that we have the overflow policies, consistency with Java's thread pools has always been a goal (Sun/Oracle has some very smart people working on this stuff). We'll make this change in the next release. |
Oh awesome, looks like I discovered this gem right at the point when you had added enough for me to use it, I didn't realize the overflow policies were a recent addition! Awesome. |
If an executor has a handle_overflow method defined, use that in the case where we post to an executor which is not running. If no handle_overflow method is defined (e.g. for the single-thread executor), preserve the current behaviour of returning false. Fixes Github issue ruby-concurrency#192.
This behavior has been implemented for pure-Ruby thread pools, but still needs implemented for the JRuby-optimized thread pools. |
Awesome. I'm surprised the JRuby optimized thread pools don't already do it if they are using java.util.concurrent.ThreadExecutor under the hood which does it itself. But if it would be helpful for me to try and help, I can try to find time to take a look and make a PR? Did you already add tests for this behavior that run against the pure-ruby version, and can be run against the Java version too to confirm? Or would be that be the place to start? Do you guys already have a test infrastructure that tests everything against multiple environments to ensure consistent behavior? |
@jrochkind The JRuby thread pools are just a thin wrapper over |
If you post to a threadpool that is in
shutdown?
state, your work does not get executed and the call returnsfalse
.What I would have expected instead, is following whatever is the pool's
overflow_policy
-- raise an exception for :abort, run in caller thread for :caller_runs, and only return without complaining (maybe returningfalse
, sure) for:discard
.But is the present behavior what the java.util.concurrent stuff does? Maybe they have some reason for it, I guess, and I understand wanting to stay consistent. But following the
overflow_policy
seems more useful and expected to me.It is surprising to me to have to check the return value of #post to know if the work is actually going to be done, I'd expect an RejectedExcecution exception by default if posting to a shutdown pool (and since overflow_policy is abort by default, that's what I'd get if it followed overflow policy)
The text was updated successfully, but these errors were encountered: