Closed bensheldon closed 10 months ago
5.times do
Thread.new do
if pool.available_worker_count > 0 # query
pool << proc {...} # use
end
end
end
This PR encourages time-of-check / time-of-use race conditions.
While I see the value of this interface/method, I don't think it solves the original problem.
Given that max_queue: 0
== unbounded queue is probably impossible to change, maybe we should implement the desired behaviour with max_queue: nil
.
Alternatively, if we think that is a terrible idea (consistency max_queue: 1
vs max_queue: 0
is definitely confusing), then another option is to deprecate the current syntax, release that, rework the interface, and then release that some time later.
max_queue: 0
and max_queue: nil
the same but issue a deprecation warning for the former.max_queue: 0
do the logical thing.I'm OK to add this as a monitoring method, and of course yeah it's always potentially stale info, as for other monitoring methods.
It doesn't address #684 though, we'd probably need to fix the ThreadPoolExecutor to handle having a not-unlimited queue.
@eregon max_queue: 0
=> unbounded. To me, that's pretty confusing. However, code search reveals at least some usage. My concern is, those people may have been expecting a queue of size 0.
What do you think of using max_queue: nil
to mean no queue?
oh! I think I understand this queuing thing better. The synchronous: true
option is actually synonymous with "no queue", and easier to understand in the JavaThreadPoolExecutor because a SynchronousQueue
is no queue at all ("A synchronous queue does not have any internal capacity, not even a capacity of one."):
...though confusingly it must be combined with max_queue: 0
.
I don't object if we wanted to say max_queue: nil
was just shorthand for max_queue: 0, synchronous: true
Connects to #684.
I called it "available" becauseready
means the thread has already been created but is idle, which isn't inclusive of uncreated workers that could still be added to the pool.This exposes the equivalent of the Java ThreadPoolExecutor's
getActiveCount
: "Returns the approximate number of threads that are actively executing tasks."