You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by maoling <gi...@git.apache.org> on 2017/08/29 13:30:36 UTC

[GitHub] zookeeper pull request #303: ZOOKEEPER-2840: Should using `System.nanoTime()...

Github user maoling commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/303#discussion_r135789082
  
    --- Diff: src/java/main/org/apache/zookeeper/client/StaticHostProvider.java ---
    @@ -71,7 +71,7 @@
          *             if serverAddresses is empty or resolves to an empty list
          */
         public StaticHostProvider(Collection<InetSocketAddress> serverAddresses) {
    -       sourceOfRandomness = new Random(System.currentTimeMillis() ^ this.hashCode());
    +       sourceOfRandomness = new Random(System.nanoTime() ^ this.hashCode());
    --- End diff --
    
    @asdf2014 
    - shift right a space(haha,original code is also not alignment)
    - according to [ZOOKEEPER-1990](https://issues.apache.org/jira/browse/ZOOKEEPER-1990)
       >    the goal here is to make sure that when multiple client threads start at the same time on the same machine 
             (such as in our systest) and execute this line each one is likely to have a different random seed.
    - your demo is not convincing because different client have different values of `this.hashCode()`(different instances) although the elements in inetSocketAddressesList is same. Look at my [demo](https://github.com/maoling/fuck_zookeeper/blob/master/src/java/test/com/apache/zookeeper/self/ZOOKEEPER_2840.java)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---