This is an automated email from the ASF dual-hosted git repository. sijie pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push: new 1f0f92c OrderedScheduler#chooseThread(key) handle null key 1f0f92c is described below commit 1f0f92c0c0cfc0cafe0cab976d8c5fbdf34c10d3 Author: Sijie Guo <si...@apache.org> AuthorDate: Mon Apr 30 16:29:08 2018 -0700 OrderedScheduler#chooseThread(key) handle null key Descriptions of the changes in this PR: *Motivation* It is more convenient if OrderedScheduler#chooseThread(key) can handle null key. so the applications who is using #chooseThread don't need to worry which method to choose - `chooseThread()` vs `chooseThread(key)`. *Solution* in `chooseThread(key)`, fallback to randomly pickup a thread if key is null. Author: Sijie Guo <si...@apache.org> Reviewers: Enrico Olivelli <eolive...@gmail.com>, Jia Zhai <None> This closes #1372 from sijie/order_scheduler_null_key --- .../java/org/apache/bookkeeper/common/util/OrderedExecutor.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java b/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java index 0f634d0..6a86141 100644 --- a/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java +++ b/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/util/OrderedExecutor.java @@ -348,7 +348,11 @@ public class OrderedExecutor implements ExecutorService { return threads[0]; } - return threads[MathUtils.signSafeMod(orderingKey.hashCode(), threads.length)]; + if (null == orderingKey) { + return threads[rand.nextInt(threads.length)]; + } else { + return threads[MathUtils.signSafeMod(orderingKey.hashCode(), threads.length)]; + } } /** -- To stop receiving notification emails like this one, please contact si...@apache.org.